can you help me solve this problem..

how can i make a program that will make the number i input to words..

numbers from 0-9999

using only the case..

the only thing i know is the numbers up to 0-9.. please help me..

Printable View

- 02-14-2011janjana program that will make the number i input to words
can you help me solve this problem..

how can i make a program that will make the number i input to words..

numbers from 0-9999

using only the case..

the only thing i know is the numbers up to 0-9.. please help me.. - 02-14-2011Salem
So show us your best effort to date.

- 02-14-2011codeprada
i can give a quick run down of what your code should look like.

every number follows a particular pattern.

1000 =**one**thousand

2000 =**two**thousand

555 = five hundred and fifty**five**

556 = five hundred and fifty**six**

810 =**eight hundred and**ten

820 =**eight hundred and**twenty

this is the part where u have to use your brain. finding out what pattern the number applies to.

you must test each number like this (since 9999 is the highest number you want to go to i'll use that as my high range)

Code:`int x = 9999;`

have a switch statement that'll change the 9 to nine and concat thousand on it.

this small piece of code will ensure that x has 1 less place (in this case the thousands place)

Code:`x = x % 1000; //x will be 999`

Code:`x = x % 100; //x will be 99`

don't forget

Code:`x = x % 10; //x will be 9`

to test for numbers like 100, 5000....etc will return 0 when u do the MOD % operation on them.

Code:`6000 % 1000 //returns 0`

Code:`500 % 100 //returns 0`

Code:`6000 % 100 //WRONG: returns 60 and definitely not what we want here`

**hope u understand the very simple logic i'm trying to show you since we know 9999 will be the highest number and btw nested switch statements is the way to go.** - 02-14-2011bobknows
do you have to set the first 2 digits as one string or is there a way to make it say thirteen, fourteen, fifteen.... without having to make 100 seperate strings for the first 2 digits?

- 02-14-2011codeprada
other than writing it out manually which a switch statement the only other thing that comes to mind are maps

Code:`#include <map>`

...

...

int main()

{

map<int, string> numbers;

numbers.insert(make_pair(11,"eleven"));

numbers.insert(make_pair(12,"twelve"));

...

...

numbers.insert(make_pair(19,"nineteen"));

return 0;

}