82.8k views
1 vote
Int OutsideTemp;

cout << "Enter today’s high temperature";
cin >> OutsideTemp;

Code the statements that test to see if OutsideTemp is above 100 or below 20. If so display to the screen "The temperature is dangerous today" otherwise display to the screen "Today is a great day".

User Reddirt
by
6.7k points

1 Answer

2 votes

Answer:

The cpp program is given below.

#include <stdio.h>

#include <iostream>

using namespace std;

int main()

OutsideTemp<20)

std::cout << "The temperature is dangerous today" << std::endl;

else

std::cout << "Today is a great day" << std::endl;

//program terminates

return 0;

OUTPUT1

Enter today's high temperature: 125

The temperature is dangerous today

OUTPUT2

Enter today's high temperature: 55

Today is a great day

Step-by-step explanation:

1. The header files and namespace are included as per the norm.

2. The given code declares the integer variable, OutsideTemp, and takes user input for this variable.

3. The variable, OutsideTemp, is tested using if-else statements.

4. The if clause contains two conditions for testing. Both conditions are combined using OR operator. The OR operator is same for cpp, java, c sharp languages, which have originated from C and support object-oriented concepts.

5. The else clause contains the code to be executed outside the conditions.

6. Both the if-else statements display the message to the user based on testing conditions. A new line is inserted before displaying the output using keyword, endl.

7. The main() method has integer return type hence, program ends successfully with a return statement.

8. In cpp, code is not mandatorily written inside class as cpp is not purely object-oriented language.

9. The given program is tested two times to test both, if and else clauses.

10. The result for both executions is shown.

11. The cpp languages uses cin keyword to take user input and cout keyword to print the result.

12. If the coding has an error such as referencing outdated keywords, the message is displayed in red and contains the given statement.

returned 1 exit status

13. Hence, return 0 assures that the program executed successfully and has ended.

User Lea A
by
6.7k points