Well I have started writing a code to create this program that i have to have done by tommorow but i am stuck at the moment. Anybody please help!!

Here is the problem:

Write a prgram that converts numbers to words. For examlpe, 834 should result in "eight three four." Likewise, 1697 should convert to "one six seven nine." You may assume that the input is less than one million. (Hint: remember the % operator!).

Is there anybody that can help me out with this?? Thanks!

2. What have you tried?

3. Posted in other topic.

Originally Posted by King Mir

Here's a hint:

1893%10=3
1893/10=189
189%10=9
189/10=18
etc.

4. So how do I make the actual conversion from number to text?

5. http://cboard.cprogramming.com/searc...earchid=543735

Look at that, that's the result of the board search for "numbers to words". You're likely to find an answer there.

6. you use either if-else or switch():

example:

Code:
```switch(num) {
case 1: puts("one"); break;
case 2: puts("two"); break;
.....
default: puts("Invalid Input"); break;
}```
where num holds the value returned by the modulo operation, not the division.

also, in the loop:

Code:
```while((input % 10) != 0) {
num=input%10;
input=input/10;
switch(num) {
...
}
}```
hope this helps.

7. I have came up with this code but everything prints out backwards. EX. I input 123 and it will output three, two, one. How do I fix this part?

Here is what I have so far:

Code:
```#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int number, input;
scanf("%d", &input);
while ((input < 0.0) || (input > 1000000.0))
{
printf("\nError! Enat a number between 0 and 1,000,000! Try again: ");
scanf("%d", &input);
printf("\n");
}
while((input % 10) != 0) {
number=input%10;
input=input/10;
switch(number) {
case 1: puts("one"); break;
case 2: puts("two"); break;
case 3: puts("three"); break;
case 4: puts("four"); break;
case 5: puts("five"); break;
case 6: puts("six"); break;
case 7: puts("seven"); break;
case 8: puts("eight"); break;
case 9: puts("nine"); break;
default: puts("Invalid Input"); break;
}
}
getchar();
getchar();
return(0);
}```

8. [input] is uninitialized. Turn on all warnings in your compiler. If the compiler doesn't say a word, it's about time to switch.
Why compare [input], which is an int, to 1000000.0, which is a floating-point number?
Why use double getchar()s? Why use getchar() at all? Run your program from command line, like all real men do.
You can also remove the default: case; [number] should never be any other value.

You can put the results so far into an array, then output the array in reverse. Assuming, of course, that you've learned arrays already...

9. Originally Posted by jafet
[input] is uninitialized. Turn on all warnings in your compiler. If the compiler doesn't say a word, it's about time to switch.
Why compare [input], which is an int, to 1000000.0, which is a floating-point number?
Why use double getchar()s? Why use getchar() at all? Run your program from command line, like all real men do.
You can also remove the default: case; [number] should never be any other value.

You can put the results so far into an array, then output the array in reverse. Assuming, of course, that you've learned arrays already...
1. Input doesn't NEED to be initialized.

2. I agree that comparing an int to a float is wrong, and should be changed.

3. I assume he IS running his program from command line "like all real men", and thats EXACTLY why he's using getchar(), so it doesnt (compile. close.) in an instant.

4. Is there something wrong with safe habits like always putting a default? I think not

5. Im sure he's thankful for the suggestion, but the opposite for you elitist attitude.

10. Cpre 185 at ISU eh? lol. Btw, I'm also having he same problem that my words print out backwards. How can you fix this? No, I haven't learned arrays yet.

11. Originally Posted by JDD
3. I assume he IS running his program from command line "like all real men", and thats EXACTLY why he's using getchar(), so it doesnt (compile. close.) in an instant.

4. Is there something wrong with safe habits like always putting a default? I think not

5. Im sure he's thankful for the suggestion, but the opposite for you elitist attitude.
3. Have you seen this? It gets asked more times than I'd like to remember.

4. In general, no. But it does show a fundamental misunderstanding of a simple operator.

5. Sometimes the best help is accompilshed using a blunt instrument to jump start the organ between the ears.

12. Originally Posted by Dave_Sinkula
3. Have you seen this? It gets asked more times than I'd like to remember.
It was never asked in this thread, getchar() works, and it doesnt knock performance, so why NOT use it.

4. In general, no. But it does show a fundamental misunderstanding of a simple operator.
Not necessarily , it likely shows a simple habit.

5. Sometimes the best help is accompilshed using a blunt instrument to jump start the organ between the ears.
But most of the time the best help is accomplished with understand and compassion.

13. 1) Yes, I was wrong about that.

3) Do you even know what a command line is?

4) The code between default: and break; can be removed. It bloats code.

5) Some programming courses don't allow students to use constructs which have not yet been taught. (Unfortunately, yes.)

Stop playing Robin Hood, mercilessly spoonfeeding the poor and meek. I am here to solve problems, not settle differences.

14. zac_haryy, if you havent discussed arrays yet, why not have 5 integer variables (since integers can only have a max value of 64k sumthin? you could then assign them sentinel values like (-1) for instance, you then store those "switched" numbers in them, then simply switch and display them in reverse order if they dont hold the sentinel value.

15. This is a sample where you can just read it in as a char string using correct functions. Also it filters out the numbers even if the string also contains some non-numeric characters.
Code:
```#include <stdio.h>
int main(){
char buffer[256];
fgets(buffer,255,stdin);
int i;
for(i=0;buffer[i]!='\0';i++){
switch(buffer[i]) {
case '0': printf("zero "); break;
case '1': printf("one "); break;
case '2': printf("two "); break;
case '3': printf("three "); break;
case '4': printf("four "); break;
case '5': printf("five "); break;
case '6': printf("six "); break;
case '7': printf("seven "); break;
case '8': printf("eight "); break;
case '9': printf("nine "); break;
}
}
fgets(buffer,255,stdin);
}```