Complete ACTIVITY program using the following
specification:
Write a C++ program that displays a suggested
activity based on the outdoor temperature (in fahrenheit) and
whether or not it is raining/snowing. Use the following table for
suggested activities. Show both with nested loops and with logical
operators.( WRITE THE CODE VERY CLEARY SHOWING ALL THE STEPS)
Temperature |
Raining/Snowing |
Activity |
>=80 |
no |
beach volleyball |
>=80 |
yes |
movie |
<80 and >=32 |
no |
running |
<80 and >=32 |
yes |
racquetball |
<32 |
no |
ice fishing |
<32 |
yes |
skiing |
Answer:
Explanation:
temp variable stores the temperature in fahrenheit.
rain_or_snow stores yes or no (if it is raining/snowing or not)
while loop is used to take input again and again for rain_or_snow variable until user enters a "yes" or "no"
Then, if else if else blocks are used to check the values of temperature and inside the block, another if else blocks are there to check the value of rain_or_snow and print output accordingly.
Code:
#include <iostream>
using namespace std;
int main()
{
int temp;
cout<<"Enter the temperature in Fahrenheit: ";
cin>>temp;
string rain_or_snow;
cout<<"Is it raining or snowing? (yes/no): ";
cin>>rain_or_snow;
while(rain_or_snow!="yes" && rain_or_snow!="no")
{
cout<<"Please enter yes or no"<<endl;
cin>>rain_or_snow;
}
if(temp>=80)
{
if(rain_or_snow=="no")
cout<<"beach volleyball"<<endl;
else
cout<<"movie"<<endl;
}
else if(temp>=32)
{
if(rain_or_snow=="no")
cout<<"running"<<endl;
else
cout<<"racquetball"<<endl;
}
else
{
if(rain_or_snow=="no")
cout<<"ice fishing"<<endl;
else
cout<<"skiing"<<endl;
}
return 0;
}
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
Complete ACTIVITY program using the following specification: Write a C++ program that displays a suggested activity...
Write a function (NOT a complete program) that displays the following picture. Use nested for loops inside of the program. ||#|@|#|(a) | # | @ # | @ #|(a) | # | @ You do not need to ask the user for input and can assume that there are only 6 columns