Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Make a "displayWithCommas(long n)" where n for now is a
- 4 to 6 digit number. Get it to just display the "thousands"
- part and the "other" part.
- For example: displayWithCommas(12345);
- Outputs:
- 12 is the thousands.
- 345 is the other.
- */
- #include <iostream>
- using namespace std;
- void displayWithCommas(long n) {
- if (n>=1000) {
- cout << n/1000 << ",";
- }
- int other = n%1000;
- //check to see how many digits left and handle appropriately
- if ((other >= 10) && (other <=99)) {
- //2 digit number
- cout << "0" << other << endl; //0xx
- }
- else if (other < 10){
- cout << "00" << other << endl; //00x
- }
- else {
- cout << other;
- }
- }
- int main() {
- long n;
- cout << "Enter a number: ";
- cin >> n;
- displayWithCommas(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement