In: Computer Science
*In C++ language please*
Create a table that converts temperatures from Celsius to Fahrenheit
Ask the user if they would like to know today's temperatures
Hint: Run in submit mode to see the desired outputs before getting started
Celsius to Fahrenheit : Fahrenheit = Celsius *180.0 /100 + 32
Also based on the new Fahrenheit temperature output the appropriate statement below:
Please find the code , output below.
#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
string ans="yes",name;
int nameLngth;
double Fahrenheit ,Celsius;
cout<<"Would you like to know today's temperatures ? ";
cin>>ans;
while(1){
if (ans=="yes"){
cout<<"Enter your name : ";
cin>>name;
nameLngth = name.length();
srand(nameLngth);
Celsius = rand() % 99 + nameLngth;
Fahrenheit= Celsius *180.0 /100 + 32;
cout<< "Today's temparature is "<<endl;
cout <<
"Celsius"<<"\t\t"<<"Fahrenheit"<<endl;
cout <<
"---------------------------------"<<endl;
cout <<
Celsius<<"\t\t\t"<<Fahrenheit<<endl;
if (Fahrenheit<55){
cout<< "carry a hat and gloves\n";
}
else if (Fahrenheit>=55 && Fahrenheit<75){
cout<< "carry a jacket\n";
}
else if (Fahrenheit>=75 && Fahrenheit<100){
cout<< "shorts it is\n";
}
}
else{
cout<< "Goodbye "<<name;
exit(0);
}
cout<<"Would you like to know today's temperatures ? ";
cin>>ans;
}
return 0;
}
OUTPUT :