Here is the question I was trying to solve:
You are given a positive integer, n,:
If 1 ≤ n ≤ 9, print his English submission. This is “ one ” for 1, “ two ” for 2, etc.
Otherwise, type " Greater than 9 " (without quotes)
Here is part of my suggested answer, but it does not work!
int n;
if (1 <= n <= 9) {
if (n == 1) {
cout << "one" << endl;
} else if (n == 2) {
cout << "two" << endl;
} else if (n == 3) {
cout << "three" << endl;
} else if (n == 4) {
cout << "four" << endl;
} else if (n == 5) {
cout << "five" << endl;
} else if (n == 6) {
cout << "six" << endl;
} else if (n == 7) {
cout << "seven" << endl;
} else if (n == 8) {
cout << "eight" << endl;
} else if (n == 9) {
cout << "nine" << endl;
}
} else {
cout << "Greater than 9" << endl;
}
What is the problem with the code?
source
share