I am taking a beginners C++ class and I do not know how to even begin this assignment. Can anyone help?
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 – Work hard and play hard.
Hint: Use if and else if statements
*** Sample output
Please enter temporature: .5
Is it Sunday(Yes=1, No=2)? 1
Work hard and play hard.
Please enter temporature: -8
Is it Sunday(Yes=1, No=2)? 2
Dress warm.
Here is what I have so far
#include <iostream>
using namespace std;
int main ()
{
Cout << "Please enter temperature: ";
Cin >> temperature;
Cout << "Is it Sunday(Yes=1, No=2)? "
Cin >> dayOfweek;
If ((temperature < -10) && (dayOfWeek == 1) ) {
Cout << "Stay home" << endl;
} else if ((temperature < -10) && (dayOfWeek != 1) ) {
Cout << "Stay home, but call work" << endl;
} else if ( (temperature <= 0) && (temperature >= -10)) {
Cout << "Dress warm" << endl;
} else {
Cout << "Work hard and play hard" << endl;
}
Last edited on
Hi dreamrestorer, welcome to cplusplus forums.
Please post your code in code tags (the <> button on the right under format.
This way we can see what you have done & point you in the right direction, but not do your homework for you.
Look forward to helping out
we are here to help you but not to do your whole code.
do you program however you know then we will fix your mistakes
Here is what I have so far
#include <iostream>
using namespace std;
int main ()
{
Cout << "Please enter temperature: ";
Cin >> temperature;
Cout << "Is it Sunday(Yes=1, No=2)? "
Cin >> dayOfweek;
If ((temperature < -10) && (dayOfWeek == 1) ) {
Cout << "Stay home" << endl;
} else if ((temperature < -10) && (dayOfWeek != 1) ) {
Cout << "Stay home, but call work" << endl;
} else if ( (temperature <= 0) && (temperature >= -10)) {
Cout << "Dress warm" << endl;
} else {
Cout << "Work hard and play hard" << endl;
}
You still didn't put your code inside the code tags. I don't see anything wrong with it, except you need to declare your variables.
Cout and Cin in your code should be cout and cin. This won't compile, but the compiler output should give some clues to the problems.
Edit: If should be if
It's better to use a switch instead of a load of else if's
As fg109 says create variables and initialise them.
Last edited on