P
promet
Hi,
I'm trying to understand if statements. I've written the following
code:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please tell me your age: \n\n";
cin>> age;
cin.ignore();
if (age < 50)
{
cout<<"You're a regular spring chicken, congratulations!\n";
}
else if ( age >= 50 && age <=70)
{
cout<<"You're still looking great, lay off the beer though!\n";
}
else if ( age >= 70 && age <= 100)
{
cout<<"You're entering the twilight of your years, make sure that your
will is in order!\n";
}
else if ( age >= 100)
{
cout<<"Daaamn Methuselah! Whether you're lucky or diligent
congratulations! Here's to clean living...\n";
}
cin.get();
}
It compiles and runs fine, but any age entered over 70 resolves to the
"You're still looking great, lay off the beer though!\n"; statement. In
my understanding the following "else if" statements should report the
other responses. Clearly I'm mistaken though. Could someone offer some
clarity here? Thanks.
promet
I'm trying to understand if statements. I've written the following
code:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Please tell me your age: \n\n";
cin>> age;
cin.ignore();
if (age < 50)
{
cout<<"You're a regular spring chicken, congratulations!\n";
}
else if ( age >= 50 && age <=70)
{
cout<<"You're still looking great, lay off the beer though!\n";
}
else if ( age >= 70 && age <= 100)
{
cout<<"You're entering the twilight of your years, make sure that your
will is in order!\n";
}
else if ( age >= 100)
{
cout<<"Daaamn Methuselah! Whether you're lucky or diligent
congratulations! Here's to clean living...\n";
}
cin.get();
}
It compiles and runs fine, but any age entered over 70 resolves to the
"You're still looking great, lay off the beer though!\n"; statement. In
my understanding the following "else if" statements should report the
other responses. Clearly I'm mistaken though. Could someone offer some
clarity here? Thanks.
promet