1. ## Commas, I'm Stumped

I've been trying to figure out how to do this for a couple weeks and I cannot figure out how to do for the life of me. I have to get a program to do this:

Enter a 4-6 digit number: 1234
The number you entered is: 1,234

or like this 12345 into 12,345

I've been told I can do this without an if-else statement and with just simple c++ I can do it. I DO NOT want the answer I'm just wondering if anyone has any hints for me or can lead me in the right direction..

I've set it up so each number the computer reads is its own variable the problem is inserting the comma when its either 12,345 or 1,234 or 123,456... The only thing I can think of is someone inserting the comma always 3 digits before the end of the decimal place. Thanks in advanced.

2. I'm just wondering if anyone has any hints for me
Hint: You can convert integer values into strings of chars that represent that number.

3. [HINT]
Well, I would take a look at the modulus operator (%) and powers of 10, aka 100, 1000, 100000.
[/HINT]

4. I've done the first suggestion. I've never been able to figure out the purpose of modulus. This is just so annoying, I just can't seem to think of anyway to do it.

5. If you did in actual fact do the first suggestion, then why don't you just go through the string backwards, and read in each element to a new string? Every third element, place a comma in the new string.

6. hint: if (number > value && number < anothervalue)
EDIT
If you do the other suggestion then just remember to check if the number has another digit after the , else you'll have something like ,123

7. Well the first suggestion makes things pretty easy.

1. get number from user
2. convert number into char array
3. count backwards from the end of the array
a. every 3rd number there should be a ',' inserted into the array

edit - FAQ int to char array

hint: if (number > value && number < anothervalue)
EDIT
If you do the other suggestion then just remember to check if the number has another digit after the , else you'll have something like ,123
That would be nice but I can't use if statements yet.

9. If you can't use ifs then I really doubt you can use strings. I am assuming you need to use the % then. If you think hard enough the answer will reveal itself...

10. I figured I would end up using modulus but I haven't been able to figure that out. lol... I know it takes the reminder but I don't know looks like I got a lot of guessing to do..

11. Look dude, just play around with it. You'll have fun. Below DOES NOT SOLVE YOUR PROBLEM. Simply points you in the right direction. You'll have to figure out the whole 0 thing:
Code:
```#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main() {

int myNumber;

cout << "Enter a number: ";
cin >> myNumber;

cout << (myNumber/1000) % 100000 <<" " << myNumber % 1000 << endl;

return 0;
}```
And my output:

12. You can do it using locales and facets but that is definitely an advanced topic. I posted an example of that in this thread a couple weeks back. It's ugly but it works. For beginners, the easiest way might be to do as suggested and convert to a character representation and work with that.

13. Thanks, at least I'm moving in a good direction now. Now I have to figure out how to add the zeros when needed.

14. I've been messing around with a bunch of combinations of % and / and adding new variables multipling and divivding the first and second part of the calculations. I tried to logically write down a piece of paper what would do it. When I enter 1200 I get 1,200 but when I got up to one more zero I get this, I enter 12,000 and get 12,0 and when I enter 120,000 I get 120,0 ... Looks like there are 2 zeros missing.. Very Confusing. lol.. Well thanks for your help everyone hopefully I'll be able to get it tommorow.

15. I was stumped with the same problem. This is what I did.
Declare a variable called big and set it equal to 1000000000. This will be the largest number that can be entered. Then use a while loop to divide big by 10 each time the loop is run. Loop while the number entered is < big. Then make another while loop to divide number by big and store that value into x. Loop until x==0.1. Then divide big by 10. And then x=number%big.
This makes u print the number one digit at a time. If big=1000, 1000000 or 1000000000 then print a comma. I will get the program to you ASAP.