Answer to Question #191853 in C++ for Flux

Question #191853

Develop a C++ program to get the temperature and print the following status according to the given temperature by using else if ladder statement in function.





1. T<=0 "Its very very cold"

2. 0 < T < 0 "Its cold"

3. 10 < T < =20 "Its cool out"

4. 20 < T < =30 "Its warm"

5. T>30 "Its hot"



1
Expert's answer
2021-05-12T18:01:05-0400
#include <iostream>

int main()
{
    std::cout << "Please input the temperature: ";

    int temperature;
    std::cin >> temperature;

    if(!std::cin)
    {
        std::cerr << "Bad input\n";
        return 1;
    }

    if(temperature <= 0)
    {
        std::cout << "Its very very cold\n";
    }
    else
    if(0 < temperature && temperature <= 10)
    {
        std::cout << "Its cold\n";
    }
    else
    if(10 < temperature && temperature <= 20)
    {
        std::cout << "Its cool out\n";
    }
    else
    if(20 < temperature && temperature <= 30)
    {
        std::cout << "Its warm\n";
    }
    else
    {
        std::cout << "Its hot\n";
    }
    
    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