Write a program that accepts two numbers – temperature and day of week (if it is Sunday 1, otherwise 2. Display the following, if:
temperature < -10 and Sunday – Stay home.
temperature < -10 and not Sunday – Stay home, but call work.
temperature <= 0 (but >= -10) – Dress warm.
temperature > 0 and Sunday – Play hard.
temperature > 0 and not Sunday – Work hard.
Hint: Use if and else if statements
*** Sample output
Please enter temperature: .5
Is it Sunday(Yes=1, No=2)? 1
Play hard.
Please enter temperature: -8
Is it Sunday(Yes=1, No=2)? 2
Dress warm.
Ok sorry guys I am a complete noobie, but here is my question that I am struggling with. It seems like I have got it mostly right, but when I try to input .5 it completely skips me being able to input the day of the week and just outputs work hard. I can put in a whole number and it seems to work fine. Is there something in particular I am missing here?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int temperature;
char weekday;
cout << "Please enter temperature: ";
cin >> temperature;
cout << "\n";
cout << "Is it Sunday(Yes=1, No=2)? ";
cin >> weekday;
cout << "\n";
if ((temperature < -10) && (weekday == 1)) {
cout << "Stay home" << endl;
}else if ((temperature < -10) && (weekday != 1)) {
cout << "Stay home, but call work" << endl;
}else if ((temperature <= 0) && (temperature >= -10)) {
cout << "Dress warm" << endl;
}else if ((temperature > 0) && (weekday == 1)){
cout << "Play hard" << endl;
}else if ((temperature > 0) && (weekday != 1)) {
cout << "Work hard" << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
|