Hi, im new to c++ and this website. Ive done some reasearch on this problem and i cant figure it out. I'm trying to use if and else statements correctly. Heres the code.
#include <iostream>
using namespace std;
int main()
{
int Ia;
cout << "How old are you?" << endl;
cin >> Ia;
if (Ia >= 35)
{ cout << "Your getting old!" << endl;
}
else (Ia <= 35);
{
cout << "Still a youngin!" << endl;
}
system ("pause");
return 0;
}
the output I get is
Your getting old!
Still a youngin!
I want it to only do one or the other depending on if the user inputs a value higher or lower than 35.
#include <iostream>
usingnamespace std;
int main() {
int Ia;
cout << "How old are you?" << endl;
cin >> Ia;
if (Ia >= 35) {
cout << "Your getting old!" << endl;
} else
(Ia <= 35);
{
cout << "Still a youngin!" << endl;
}
system ("pause");
return 0;
}
As you can see now, you made some mistakes at the else statement:
You tried to write a condition to the else, which you can't do. Instead, an elseif can have a condition. You made another mistake in the mistake (by putting a semicolon after (Ia <= 35) ), that is why it compiled. Try rewriting your code, if you still have troubles come back, and post your new code (next time in [code][/code] tags).