Information
Here is the output from the program run interactively:
Enter a two-digit integer (10-99)? (0=quit) 22 twenty-two Enter a two-digit integer (10-99)? (0=quit) 47 forty-seven Enter a two-digit integer (10-99)? (0=quit) 99 ninety-nine Enter a two-digit integer (10-99)? (0=quit) 50 fifty Enter a two-digit integer (10-99)? (0=quit) 10 ten Enter a two-digit integer (10-99)? (0=quit) 18 eighteen Enter a two-digit integer (10-99)? (0=quit) 0
The program continues to run until the user types in 0 (zero) to terminate.
The name of the file should be num2words.c and the command to compile it will look like this:
Files:gcc -Werror -Wall -Wextra -ansi -pedantic -O2 -Wno-unused-result -o num2words num2words.c main.c
You only need to include one header file (stdio.h) in your file.void number_to_words(int number);
By the way, I didn't type those 91 numbers in the file. I was too lazy to type all of those numbers manually, so I wrote a simple program to create them instead. (See, we programmers are lazy!)
Notes
and then you would print:thirty
The numbers from 10 to 19 are kind of unique and you should handle them separately. However you choose to do this: Do NOT have 90 separate if statements!!!! (Think before you start.) You will have several if...else if statements, so don't be alarmed.-eight
and then diff with the provided output.num2words < input.txt > myoutput.txt
Advanced students: If you've already programmed before, you may know that this is more easily done with pointers and arrays, and you may want to use those. After you learn about pointers and arrays, I'll suggest that all students should re-code this program using those techniques. In fact, with pointers and arrays, you could handle 3-digit and 4-digit numbers easily with only a few if...else if statements.