# a program that will make the number i input to words

This is a discussion on a program that will make the number i input to words within the C++ Programming forums, part of the General Programming Boards category; can you help me solve this problem.. how can i make a program that will make the number i input ...

1. ## a 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..

2. So show us your best effort to date.

3. 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;`
(int)(x / 1000) is going to give u 9. there you have the thousand's place.
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`
then (int)(999 / 100) gives u 9. hundreds place. a switch statement that does the same with 9 and concats hundred to the string....etc

Code:
`x = x % 100; //x will be 99`
from 99 downwards it's gonna be a little different. instead of 9 hundred and 9 thousand you must concat ninety (or eighty or seventy...you get the point ) to the string.

don't forget
Code:
`x = x % 10; //x will be 9`
pass x through switch statement again. the one's place will be either "one", "two",...."eight", "nine".

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.

4. 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?

5. Originally Posted by bobknows
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?
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;
}```