PDA

View Full Version : [SOLVED] what's wrong with the line i commented in this c++ code?



btf18
March 31st, 2011, 10:38 PM
Hi, the line near the bottom that i commented. Thanks.



#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please enter your age\n";
cin>>age;
cin.ignore();
if ( age < 100 ) {
cout<<"youre pretty young!\n"; }
else if ( age = 100 ) {
cout<<"Youre ollllld\n"; }
else ( age > 100 ) { //this line says it needs a ';' before the '{'
cout<<"youre really really old xP\n";
}
cin.get();
}

GeneralZod
March 31st, 2011, 10:52 PM
Needs to be "else if", although just "else {" (i.e. without the "( age > 100 )") would probably be better :)

Edit:

Also, "else if ( age = 100 )" should be "else if ( age == 100 )"

btf18
March 31st, 2011, 11:03 PM
Thanks man, i changed it to else without the brackets, then added the extra =, and it worked proerly :-)