Dear Bogdan321:
Hello, and a pleasant day.
Without using arrays, I strongly suggest the power of division (/) and modulus division ( % ) of the number you want to convert into words. For example, you declare something like:
987 composes of three number places: hundreds place (9), the tens place (8), and the ones place (7).
Now we need to "extract" the hundred place (9) by doing this arithmetic operation:
This will give the value of 9 to our variable
h. Then using a simple
switch/case, we could do some thing like:
switch (h) {
case 1: "one hundred "; break;
case 2: "two hundred "; break;
}
Just add more case statement until you reach
case 9 : "nine hundred "; break;
Then we only have 87. So to "extract" 87 from 987, we could use modulus division:
int hrem;
hrem = number % 100;
//add "special if/else" condition if hrem is 11,12,13,14,15,16,17,18 or 19
Now, the variable
hrem is equal to 87. Now we need to "extract" the tens place (8) by doing this arithmetic operation:
This will give the value of 8 to our variable
t. Then using a simple
switch/case, we could do something like:
switch (t) {
case 1: "ten "; break;
case 2: "twenty "; break;
}
Just add more case statement until you reach
case 9 : "ninety "; break;
Then last, you need the ones place (7). Thus:
Then using a simple
switch/case, we could do some thing like:
switch (o) {
case 1: "one "; break;
case 2: "two "; break;
}
Again, just add more case statement until you reach
case 9 : "nine "; break;
NOTE: Please take note that you need a "special" if/else condition if the variable
hrem is between 11 to 19. You may notice on my comments above.
Hope this will help you.
Thank you and God bless us all.
Respectfully Yours,
Mark Squall