The syntax for the control statement "if, else if, else" goes like this:
Code:
if (condition) {
// stuff that happens when condition is true
}
else if (other_condition) {
// stuff that happens when condition is false but other_condition is true
}
else {
// stuff that happens when condition and other_condition are both false
}
Now look at your code again...
Code:
if ( age <= 40) {
cout<<"You are pretty young!";
}
else if( age >=41, age <= 60 ) {
cout<<"You are kind of old!";
}
else ( age >= 61) {
cout<<"You are very old!";
}
There is no condition for the final "else" clause, it doesn't make sense. The compiler thinks you meant to say:
Code:
else {
( age >= 61 );
}
...which isn't what you intended.
I think this is what you actually intended...
Code:
if (age <= 40) {
cout << "You are pretty young!";
}
else if (age<= 60) {
cout << "You are kind of old!";
}
else {
cout << "You are very old!";
}