I am having an issue with a program. The prgram requirements are : Write a progr
ID: 666888 • Letter: I
Question
I am having an issue with a program. The prgram requirements are :
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.
The issue I am having is with the line (temperature <= 0 (but >= -10) – Dress warm.). This one prompts for the day no matter what and when a temperature is put in that meets this requirement it should NOT prompt for the day and instead should automatically output DRESS WARM. I cannot figure out how to make it do this. Here is what it looks like so far:
#include <iostream>
using namespace std;
int main()
{
float temperature;
int dayofweek;
cout << "Please enter temperature: ";
cin >> temperature;
std::cout << " ";
cout << "Is it Sunday(Yes=1, No=2)? ";
cin >> dayofweek;
std::cout << " ";
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 if ((temperature > 0) && (dayofweek == 1))
{cout << "Play hard." << endl;}
else {cout << "Work hard." << endl;}
return 0;
}
please help!!! THANK YOU
Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
int main(){
float temperature;
int dayofweek;
cout << "Please enter temperature : ";
cin >> temperature;
cout << ' ';
cout << "Is it Sunday(Yes=1, No=2)? ";
cin >> dayofweek;
cout << ' ';
// temperature < -10 and Sunday – Stay home.
if (temperature < -10 && dayofweek == 1)
cout << "Stay home." << endl;
// temperature < -10 and not Sunday – Stay home, but call work.
if (temperature < -10 && dayofweek == 2)
cout << "Stay home, but call work." << endl;
// temperature <= 0 (but >= -10) – Dress warm.
if (temperature >= -10 && temperature <= 0)
cout << "Dress warm" << endl;
// temperature > 0 and Sunday – Play hard.
if (temperature > 0 && dayofweek == 1)
cout << "Play hard." << endl;
// temperature > 0 and not Sunday – Work hard.
if (temperature > 0 && dayofweek == 2)
cout << "Work hard." << endl;
else
cout << "DRESS WARM." << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.