Answer to Question #333565 in C++ for Rille

Question #333565

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.

1
Expert's answer
2022-04-25T13:36:51-0400
#include <iostream>
using namespace std;

int main() {
    int Temp;
    cout<<"Enter the temperature in centigrade: ";
    cin>> Temp;
    
     if(!cin){        // validation
        cout<<"Invalid input. Must be int number"<<endl;
        cin.clear();            // clears the error flag
        exit(1);
       }
    
    if(Temp<0)
        cout << "freezing weather";
    
    else if(Temp<10)
            cout << "very cold weather";
            
    else if(Temp<20)
            cout<<"cold weather";
            
    else if(Temp<30)
            cout<<"normal in Temp";
            
    else if(Temp<40)
            cout<<"it is hot";
            
    else
        cout<<"it is very hot";    
    
    cout<<endl;    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS