I'm trying to use if
statement with multiple comparison operations but the day
variable isn't working in my if
statements.
Here's my code:
int day;
string rain;
cout << "What day of the week is it?" << endl;
cin >> day;
while (0 < day < 8)
{
cout << "Is it raining? Please type 'yes' or 'no' " << endl;
cin >> rain;
if ((0 < day < 3) && (rain == "yes"))
cout << "Read in bed" << endl;
else if ((0 < day < 3) && (rain == "no"))
cout << "Go out and play!" << endl;
else if ((2 < day < 8) && (rain == "yes"))
cout << "Take an umbrella!" << endl;
else
cout << "No umberella needed" << endl;
cout << "What day of the week is it?" << endl;
cin >> day;
}
cout << "Invalid day sorry" << endl;
Getting Read in bed
or go out and play
, but never Take an umbrella
.
My code also works if I put day = 9
.
Aucun commentaire:
Enregistrer un commentaire