Develop a C++ program to get the temperature and print the following status according to the given temperature by using else if ladder statement.
1. T<=0 "Its very very cold"
2. 0 < T <=10 "Its cold"
3. 10 < T < =20 "Its cool out"
4. 20 < T < =30 "Its warm"
5. T>30 "Its hot"
#include <iostream>
int main()
{
int T;
std::cout << "Enter the temperature: ";
std::cin >> T;
if(!std::cin)
{
std::cout << "Error: invalid data\n";
}
else
{
if(T <= 0)
std::cout << "Its very very cold";
else if(0 < T && T <= 10)
std::cout << "Its cold";
else if(10 < T && T <= 20)
std::cout << "Its cool out";
else if(20 < T && T <= 30)
std::cout << "Its warm";
else
std::cout << "Its hot";
std::cout << "\n";
}
return 0;
}
Comments
Leave a comment