In: Computer Science
– 28 – It is freezing out, wear a winter coat
29 – 49 – It is fairly cold, wear a jacket
50 – 78 – Weather is nice out, wear whatever
79 – 100 – It’s piping hot out, keep it light
Write a code snippet that asks the user to enter in the temperature
in Fahrenheit, and outputs the matching message that tells the
state of weather and what to wear. Your code should also handle
invalid input with an appropriate message : Hint (IF statement)
#include <iostream>
using namespace std;
{
// Write what goes in here
return 0;
}
Assume this has all been given, only write what goes inside the main
Code:
#include <iostream>
using namespace std;
int main()
{
double temp;
cout<<"Enter temperature in Fahrenheit: "; //get temperature from user
cin>>temp;
if(temp <= 28) //check temperature is 28 or less than 28
cout<<"\nIt is freezing out, wear a winter coat";
else if(temp >=29 && temp <= 49) //check temperature in between 29-49
cout<<"\nIt is fairly cold, wear a jacket";
else if(temp >=50 && temp <= 78) //check temperature in between 50-78
cout<<"\nWeather is nice out, wear whatever";
else if(temp >=79 && temp <= 100) //check temperature in between 79-100
cout<<"\nIt’s piping hot out, keep it light";
else
cout<<"\nInvalid temperature";
return 0;
}
Output: