Yes I know your code compiles with those commas in there, and yes I knew it would appear to work, but no it still does not do what you think it does.
Had you changed it to the following, and entered 50 when prompted, you would have then noticed that it doesn't do what you thought:
Code:
else if( age >=4100, age <= 60 ) {
I.e. no number can be both greater than 4100 and less than 60, yet it will still go into that if statement, illustrating my point.
Originally Posted by
BMJ
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!";
}
Yep, and there we have it; Unnecessary parts removed.
Good to know I'm still pretty young!