My code is printing all the output lines regardless of the data that is input.
This is for C++
Write a program that prompts the user to :
Enter the temperature
Using nested if and else statements, output the following:
If the temperature is less than 40: “it is cold”
If the temperature is greater than or equal to 40 and less then 60: “it is chilly”
If the temperature is greater than or equal to 40 and greater than or equal to 60 but less then 80: “it is nice”
If the temperature is greater than or equal to 40 and greater than or equal to 80: “it is hot”
Note: You may not use “else if” statements and you must use nested if statements.
Here is the code:
#include <iostream>
using namespace std;
int main()
{
int temp;
cout << "Enter the temperature" << endl;
cin >> temp;
if (temp < 40)
{
cout << "it is coldn";
}
if (temp < 60)
{
cout << "it is chillyn";
}
if (temp < 80)
{
cout << "it is nicen";
}
else (temp > 80);
{
cout << "it is hotn";
}
// Add your code here
return 0;
}
Ann Baumgart is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.