Build a C++ program to read the temperature in centigrade and display a suitable message according to the temperature state below: (nested-if else/switch case)
Temp <0 then freezing weather
Temp 0-10 then very cold weather
Temp 10-20 then cold weather
Temp 20-30 then normal in Temp
Temp 30-40 then it is hot
Temp >=40 then it is very hot
Example Input: 42
Expected Output: It is very hot.
Give the explanation about this program and how it works?
#include <iostream>
using namespace std;
int main()
{
int tem;
cout<<"Input:";
cin>>tem;
if(tem<0)
cout<<"freezing weather\n";
else if(tem<10)
cout<<"very cold weather\n";
else
if(tem<20)
cout<<"cold weather\n";
else
if(tem<30)
cout<<"normal in Temp\n";
else
if(tem<40)
cout<<"it\'s hot\n";
else
cout<<"it\'s very hot\n";
return 0;
}
Comments
Leave a comment