Log in

View Full Version : Using C++ (if, char or Boolean)


Sundayy
Feb 22, 2011, 10:08 AM
Using C++ (if, char or Boolean)
Write a program that asks the user for a two digit number and then prints the English word for that number.

Sample run:
Enter a two-digit number: 45
You entered the number forty-five.

PLAN: Read the number entered as an integer and then break the number up into 2 digits. (Recall how integer division and % work…if x is an int and has the value 45, then what’s x/10 and x%10?)

Basically, use one switch statement to print the word for the first digit (“twenty”, “thirty” and so forth). Use a second switch statement to print the word for the second digit.
Don’t forget the numbers between 10 and 19 require special treatment.
Make sure you only print the ‘-‘ when needed…twenty-three needs the -, thirty doesn’t