Practice Assignment

(num2words.c)

Information

  1. Write a program that prompts the user for a two-digit integer and then prints the English words for the number.

    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:

    gcc -Werror -Wall -Wextra -ansi -pedantic -O2 -Wno-unused-result -o num2words num2words.c main.c
    
    Files:

Notes

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.