C++ Formatting Question

GimpyFuzznut

Senior member
Sep 2, 2002
347
0
0
I'm working on an assignment for a programming class and the teacher assigned a really silly problem. He wants us to create a function that takes a integer number between 0 and 500 and outputs it in English. For example, 321 becomes three hundred twenty one. I've basically got the program working and I tested all possibilities using a loop.

Now the question I have is - is there any formatting code that would automatically make the first letter of the proceeding output capital? I don't think this really matters a big deal but it would just be something nice to have. To do this using the function, I would basically have to double or maybe triple the size. Should I just leave it as is in all lower case or maybe all uppercase? I know its a silly thing to be picky about but you never know what a teacher will find to take marks off for.

See code attached if you are curious. Also, while I'm sure people on this forum are great for providing help, are there any student-oriented programming forums/websites? Any other comments about the program are appreciated also.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Yuck.

char numbers = ["zero", "one", "two", "three", ...];

int thousands = number / 1000 whatever;
int hundreds = number / 100 whatever;
...

cout << numbers[thousnads] << " thousand " << numbers[hudnreds] << "hundred " << (special case for 10-90) << number[ones] << endl;
 

Syppion

Member
Jul 23, 2005
37
0
61
Of course there are several other methods to do this, but I can think of two fairly simple ones that may be within the scope of what your teacher has already covered.

Instead of directly outputting (via cout) the next part you could append an output string with the next part using only lower-case. Once you have finished building the output string, simply convert the first element (char) to upper-case (stringout[0]+= 'A'-'a';).
Then cout the entire stringout.

Another option is to a pair of (static) strings containing the entire alphabet- one lower-case and one uppper-case. The search the lowercase alpha-string for the element that matches the first element of the output string, and substitute it with that element of the uppercase alpha-string.

As far as helpful websites codeproject.com is one of the more popular ones - google groups can also be helpful.