In: Computer Science
C++ Code:
#include <iostream>
#include<stdlib.h>
using namespace std;
double FtoK(double f){
return (f - 32) * (5/9) + 273.15;
}
double FtoC(double f){
return ((f - 32) * 0.55);
}
double FtoN(double f){
return ((f - 32)*(0.18333));
}
int main() {
char sel='\0';
double temp;
while(sel!='X' || sel!='x'){
cout<<"C: Fahrenheit to celcius\nK: Fahrenheit to Kelvin\nN: Fahrenheit to Newton\nX: Exit"<<endl;
cin>>sel;
switch(sel){
case 'C':
case 'c':
double res;
cout<<"Enter temprature in Fahrenheit: ";
cin>>temp;
res=FtoC(temp);
cout<<temp<<" F = "<<res<<" C"<<endl;
break;
case 'K':
case 'k':
double res1;
cout<<"Enter temprature in Fahrenheit: ";
cin>>temp;
res1=FtoK(temp);
cout<<temp<<" F = "<<res1<<" K"<<endl;
break;
case 'N':
case 'n':
double res2;
cout<<"Enter temprature in Fahrenheit: ";
cin>>temp;
res2=FtoN(temp);
cout<<temp<<" F = "<<res2<<" N"<<endl;
break;
case 'X':
case 'x':
exit(0);
default:
cout<<"Wrong input"<<endl;
}
}
}
if you like the answer please provide a thumbs up.