81.4k views
0 votes
Decide what activity is most appropriate based on the temperature. If the temperature is greater than 80 degrees, then display the message "Go swimming." If the temperature is between 60 and 80 degrees, display the message "Go biking". If the temperature is less than 60 degrees, display the message "Go for a walk". The input will be the temperature.

1 Answer

3 votes

Answer:

Here is the C++ program:

#include <iostream> //to use input output functions

using namespace std; //to access objects like cin cout

int main(){// start of main function

int temp; //declare a variable to store value for temperature

cout<<"Enter temperature: "; //prompts user to enter temperature

cin>>temp; //reads value of temp from user

if(temp>80) //if temperature is greater than 80 degrees

{ cout<<"Go swimming"; } //displays Go swimming

else if(temp<=80&&temp>=60) //if temperature is between 60 and 80

{ cout<<"Go biking"; } //displays Go biking

else //if temperature is less than 60 degress

cout<<"Go for a walk"; } //displays Go for a walk

Step-by-step explanation:

The program prompts the user to enter value of temperature. It stores the value of temperature in temp variable. Then the first if condition checks if the value of temp is greater than 80. If it evaluates to true, then the print statement inside the body of this if statement executes which is "Go swimming". If this condition evaluates to false then program moves to the else if condition which checks if the value of temp is between 60 and 80. There is a logical operator AND (&&) is used between both expressions to check temperature between two ranges. If it evaluates to true, then the print statement inside the body of this if statement executes which is "Go biking". If this condition evaluates to false then program moves to the else part which has a print statement that displays "Go for a walk" on output screen. The screenshot of program along with its output is attached.

Decide what activity is most appropriate based on the temperature. If the temperature-example-1
User Cacoon
by
5.7k points