Asked by Sundayy
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
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
Answers
Answered by
MathMate
The instructions are quite detailed.
If you have used arrays, the problem will be much simplified, for example, with an array for {"one","two",...}
or {"twenty","thirty",....}
Otherwise, it can be implemented using a series of "if"s, assuming the switch statement is not allowed.
Post what you have and tell us what help you need for the logic or the code.
If you have used arrays, the problem will be much simplified, for example, with an array for {"one","two",...}
or {"twenty","thirty",....}
Otherwise, it can be implemented using a series of "if"s, assuming the switch statement is not allowed.
Post what you have and tell us what help you need for the logic or the code.
Answered by
Roy
int x;
char* y,z;
cout<<"Please enter number: "<<endl;
cin>>x;
if (x<20)
y[x-1]={"one","two",...,"nineteen"};
else
if((x/10)==2)
z[x%10]={"one","two",...,"nine"};
y[]={"twenty - ",z};
... //same for 3,4,5,6,7,8,9
cout<<"You have entered"<<*y<<endl;
//I hope this works
char* y,z;
cout<<"Please enter number: "<<endl;
cin>>x;
if (x<20)
y[x-1]={"one","two",...,"nineteen"};
else
if((x/10)==2)
z[x%10]={"one","two",...,"nine"};
y[]={"twenty - ",z};
... //same for 3,4,5,6,7,8,9
cout<<"You have entered"<<*y<<endl;
//I hope this works
There are no AI answers yet. The ability to request AI answers is coming soon!