Write a C++ program that accepts a number followed by one space and then a letter. If the letter following the number is an f, the program should treat the number entered as a temperature in degrees Fahrenheit, convert the number to the equivalent degrees Celsius, and print a suitable display message. If the letter following the number is a c, the program should treat the number entered as a temperature in Celsius, convert the number to the equivalent degrees Fahrenheit, and print a suitable display message. If the lette is neither an f or c, the program should print a message that the data entered is incorrect and then terminate. Use an if-else If chain in your program and make use of the conversion formulas:
Celsius = (5.0/9.0) *(Fahrenheit – 32.0)
Fahrenheit = (9.0/5.0) * Celsius + 32.0)
Code:
#include
using namespace std;
int main()
{double temp,ans;
char ch;
cout<<"Enter tempurature: ";
cin>>temp>>ch;
if(ch=='C'||ch=='c'){
ans= (9.0/5.0) * temp +32.0;
cout<<"Temperature in Fahrenheit : "<
else if(ch=='F'||ch=='f'){
ans=(5.0/9.0) *(temp-32.0);
cout<<"Temperature in Celcius : "<
else{
cout<<"Incorrect symbol";
}
return 0;
}
Output:
Enter tempurature: 104 f
Temperature in Celcius : 40 C
You might also like to view...
According to the Jain worldview, liberated souls __________
a. are extinguished, never to return to life in the body b. are reborn as tirthankaras c. dwell eternally in full consciousness, knowledge, and bliss d. fade into nothingness e. live eternally with Vishnu
Guru Har Krishan accomplished which of the following acts?
a. founded the Khalsa b. founded the Gurdwara Bangla Sahib in Delhi c. founded the Siks religion d. assisted in the partitioning of the Punjab
Heidegger appears to argue that the Holocaust and mechanized agriculture are on the same moral plane
Indicate whether the statement is true or false.
Shamans focus only on healing physical illness
Indicate whether the statement is true or false