### can't do the hundreds

i made a program that converts digit numbers into letter numbers, with 2 digit numbers i had no problem, but with 3 digits i can't figure out how to do it
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162`` ``````#include using namespace std; int main (){ int num; cout << "enter a number: "; cin >> num; int decimals=num%10; int tens=num/10; int hundredths=num/100; if(num<10){ switch(num){ case 1 : cout << "one" << endl; break; case 2 : cout << "two" << endl; break; case 3 : cout << "three" << endl; break; case 4 : cout << "four" << endl; break; case 5 : cout << "five" << endl; break; case 6 : cout << "six" << endl; break; case 7 : cout << "seven" << endl; break; case 8 : cout << "eight" << endl; break; case 9 : cout << "nine" << endl; break; default : cout << "error" << endl; }} if (num>=100&&num<1000){ switch(hundredths){ case 1 : cout << "onehundred"; break; case 2 : cout << "twohundred"; break; case 3 : cout << "threehundred"; break; case 4 : cout << "fourhundred"; break; case 5 : cout << "fivehundred"; break; case 6 : cout << "sixhundred"; break; case 7 : cout << "sevenhundred"; break; case 8 : cout << "eighthundred"; break; case 9 : cout << "ninehundred"; break; default : cout << " "; } switch(tens){ case 2 : cout << "twenty"; break; case 3 : cout << "thirty"; break; case 4 : cout << "fourty"; break; case 5 : cout << "fifty"; break; case 6 : cout << "sixty"; break; case 7 : cout << "seventy"; break; case 8 : cout << "eighty"; break; case 9 : cout << "ninety"; break; default : cout << "error"; } switch(decimals){ case 1 : cout << "one" << endl; break; case 2 : cout << "two" << endl; break; case 3 : cout << "three" << endl; break; case 4 : cout << "four" << endl; break; case 5 : cout << "five" << endl; break; case 6 : cout << "six" << endl; break; case 7 : cout << "seven" << endl; break; case 8 : cout << "eight" << endl; break; case 9 : cout << "nine" << endl; break; default : cout << "error" << endl; }} if(num>=20&&num<100){ switch(tens){ case 2 : cout << "twenty"; break; case 3 : cout << "thirty"; break; case 4 : cout << "fourty"; break; case 5 : cout << "fifty"; break; case 6 : cout << "sixty"; break; case 7 : cout << "seventy"; break; case 8 : cout << "eighty"; break; case 9 : cout << "ninety"; break; default : cout << "error"; } switch(decimals){ case 1 : cout << "one" << endl; break; case 2 : cout << "two" << endl; break; case 3 : cout << "three" << endl; break; case 4 : cout << "four" << endl; break; case 5 : cout << "five" << endl; break; case 6 : cout << "six" << endl; break; case 7 : cout << "seven" << endl; break; case 8 : cout << "eight" << endl; break; case 9 : cout << "nine" << endl; break; default : cout << "error" << endl; }} if(num>9&&num<20){ switch(num){ case 10 : cout << "ten" << endl; break; case 11 : cout << "eleven" << endl; break; case 12 : cout << "twelve" << endl; break; case 13 : cout << "thirteen" << endl; break; case 14 : cout << "fourteen" << endl; break; case 15 : cout << "fifteen" << endl; break; case 16 : cout << "sixteen" << endl; break; case 17 : cout << "seventeen" << endl; break; case 18 : cout << "eighteen" << endl; break; case 19 : cout << "nineteen" << endl; break; default : cout << "error" << endl; }} system("pause"); return 0; }``````
If you have more than 2 digits number you will have to use % 10 on the tens as well.
`int tens = (num / 10) % 10;`
closed account (2NywAqkS)
Not that it matters all that much, but I'd use "\n" instead of endl and avoid system("pause") in any serious programming.
Topic archived. No new replies allowed.