Question #16506

write a program which displays a menu for temperature conversion; user will choose an option from the menu and program converts temperature for selected option. (use temperature conversion formula C/5=F-32/9=R/4)
SAMPLE OUTPUT:
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
3. Celsius to Reaumur
4. Reaumur to Celsius

Expert's answer

#include "iostream"

using namespace std;

char s1, s2;

float t, T;

void main(){

cout<<"enter \"c\" for Celsius, \"f\" for Fahrenheit, \"r\" for Reaumur: ";

cin>>s1;

cout<<"enter the temparature value: ";

cin>>t;

cout<<"enter the system you want convert to (\"c\" for Celsius, \"f\" for Fahrenheit, \"r\" for Reaumur): ";

cin>>s2;

if (s1==s2) T=t;

if ((s1=='c')&&(s2=='f')) T = 9*t/5+32;

if ((s1=='c')&&(s2=='r')) T = 4*t/5;

if ((s1=='f')&&(s2=='c')) T = 5*(t-32)/9;

if ((s1=='f')&&(s2=='r')) T = 4*(t-32)/9;

if ((s1=='r')&&(s2=='c')) T = 5*t/4;

if ((s1=='r')&&(s2=='f')) T = 9*t/4+32;

cout<<t<<s1<<" = "<<T<<s2<<"\n";

system("pause");

}

using namespace std;

char s1, s2;

float t, T;

void main(){

cout<<"enter \"c\" for Celsius, \"f\" for Fahrenheit, \"r\" for Reaumur: ";

cin>>s1;

cout<<"enter the temparature value: ";

cin>>t;

cout<<"enter the system you want convert to (\"c\" for Celsius, \"f\" for Fahrenheit, \"r\" for Reaumur): ";

cin>>s2;

if (s1==s2) T=t;

if ((s1=='c')&&(s2=='f')) T = 9*t/5+32;

if ((s1=='c')&&(s2=='r')) T = 4*t/5;

if ((s1=='f')&&(s2=='c')) T = 5*(t-32)/9;

if ((s1=='f')&&(s2=='r')) T = 4*(t-32)/9;

if ((s1=='r')&&(s2=='c')) T = 5*t/4;

if ((s1=='r')&&(s2=='f')) T = 9*t/4+32;

cout<<t<<s1<<" = "<<T<<s2<<"\n";

system("pause");

}

## Comments

## Leave a comment