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

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.

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

Here's a C++ program that asks the user for a two-digit number and prints the corresponding English word for that number:

```cpp
#include <iostream>
using namespace std;

int main() {
int number;
string word = "";

cout << "Enter a two-digit number: ";
cin >> number;

int firstDigit = number / 10;
int secondDigit = number % 10;

switch (firstDigit) {
case 2:
word += "twenty";
break;
case 3:
word += "thirty";
break;
case 4:
word += "forty";
break;
case 5:
word += "fifty";
break;
case 6:
word += "sixty";
break;
case 7:
word += "seventy";
break;
case 8:
word += "eighty";
break;
case 9:
word += "ninety";
break;
default:
break;
}

if (firstDigit != 1) {
switch (secondDigit) {
case 1:
word += "-one";
break;
case 2:
word += "-two";
break;
case 3:
word += "-three";
break;
case 4:
word += "-four";
break;
case 5:
word += "-five";
break;
case 6:
word += "-six";
break;
case 7:
word += "-seven";
break;
case 8:
word += "-eight";
break;
case 9:
word += "-nine";
break;
default:
break;
}
} else {
switch (number) {
case 10:
word = "ten";
break;
case 11:
word = "eleven";
break;
case 12:
word = "twelve";
break;
case 13:
word = "thirteen";
break;
case 14:
word = "fourteen";
break;
case 15:
word = "fifteen";
break;
case 16:
word = "sixteen";
break;
case 17:
word = "seventeen";
break;
case 18:
word = "eighteen";
break;
case 19:
word = "nineteen";
break;
default:
break;
}
}

cout << "You entered the number " << word << "." << endl;

return 0;
}
```

Explanation:
1. First, we declare an integer variable `number` to store the user input, and a string variable `word` to store the English word for the number.
2. We prompt the user to enter a two-digit number using `cout`.
3. We read the number using `cin` and store it in the `number` variable.
4. We separate the number into its two digits: the first digit is obtained by dividing the number by 10 using the `/` operator, and the second digit is obtained by taking the modulo 10 using the `%` operator.
5. We use a switch statement on the first digit to determine the corresponding word for that digit. For digits 2 to 9, we concatenate the corresponding word ("twenty", "thirty", etc.) to the `word` string. For the digit 1, we go to step 7.
6. If the first digit is not 1 (i.e., it is 2 to 9), we use another switch statement on the second digit to determine the corresponding word for that digit. We concatenate the corresponding word ("one", "two", etc.) with a hyphen ("-") to the `word` string. If the first digit is 1, we skip this step and go to step 8.
7. We use a switch statement on the entire number (when the first digit is 1) to determine the corresponding word. For example, if the number is 10, we set `word` to "ten". If the number is 11, we set `word` to "eleven", and so on.
8. Finally, we print the result by concatenating the `word` string with a message using `cout`.

Note: This program assumes that the user will correctly enter a two-digit number (between 10 and 99).