if statement trouble

I have to make a program where it prompts the user to input a number between "zero" and "nineteen" and then have it translate it into spanish. If the number is not between zero or nineteen, I need to cout<< a certain statement.
So far this is what I have

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  //initializing a bunch of strings to equal the translation for that number
  //ex: string zero = "cero";
  //Then I initialize number to be a string
  

  //Then I have an infinite for loop
  //In that for loop I have the following

  cout << "Number, please: ";
  cin >> number;
		
	if (number == "zero")
	{
		cout << "In Spanish that is " << zero << '.' << endl;
	}
	if (number == "one")
	{
		cout << "In Spanish that is " << one << '.' << endl;
	}
	if (number == "two")
	{
		cout << "In Spanish that is " << two << '.' << endl;
	}
  //I continue this all the way to nineteen 


What I'm having trouble with is having a statement that couts if the number they enter isn't zero through nineteen


EDIT: Fixed it!
I changed the if statements to else if, and then the error message was a plain else statement
Last edited on
i dont think you need a string variable, most of us type symbols (123...).
You can use the else statement:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  cout << "Number, please: ";
  cin >> number;
		
	if (number == "zero")
	{
		cout << "In Spanish that is " << zero << '.' << endl;
	}
	if (number == "one")
	{
		cout << "In Spanish that is " << one << '.' << endl;
	}
	if (number == "two")
	{
	        cout << "In Spanish that is " << two << '.' << endl;
	}
        else
        {
                cout << "Invalid input " << number;
        }
@Sweet
I tried that, unfortuantely for everything I type in, it will cout the "Invalid input" line

So if I put in "one"
it will out put:

In Spanish that is uno.
Sorry my vocabulary doesn't include one.


except for the last if statement which is number nineteen, if I type in nineteen, then I get this:

In Spanish that is diecenueve.
Last edited on
@Mint
It's a homework problem, and the user has to input a number though a word unfortunately
Topic archived. No new replies allowed.