Hello I am attempting to write a program that will convert temperature from c to f and vise versa. However I need this program to stop when choice == 'q' and i am having a horrible time with it. here is the code that i have been working with. any help would be much appreciated thanks.
#include<iostream>
using namespace std;
int main()
{
const double CtoF = 1.8;
const double FtoC = 5.0/9;
char choice;
double deg;
double convFtoC;
double convCtoF;
cout<<"This program will convert a temperature from one scale to the other. "<<endl;
cout<<"Choose one of the following.... "<<endl;
cout<<"C: to convert from Celsius to Fahrenheit"<<endl;
cout<<"F: to convert from Fahrenheit to Celsius"<<endl;
cout<<"Q: to quit the program"<<endl;
cout<<"Enter your choice: "<<endl;
cin>>choice;
while(choice == 'c' || choice == 'f')
{
if(choice == 'c')
{
cout<<"Enter your Celsius temperature to convert: "<<endl;
cin>>deg;
convCtoF = (deg * CtoF) + 32;
cout<<deg<<" degrees Celsius is "<<convCtoF<<" degrees Fahrenheit"<<endl;
cout<<"Choose one of the following.... "<<endl;
cout<<"C: to convert from Celsius to Fahrenheit"<<endl;
cout<<"F: to convert from Fahrenheit to Celsius"<<endl;
cout<<"Q: to quit the program"<<endl;
cout<<"Enter your choice: "<<endl;
cin>>choice;
}
else if(choice == 'f')
{
cout<<"Enter your Fahrenheit temperature to convert: "<<endl;
cin>>deg;
convFtoC = (deg - 32) * FtoC;
cout<<deg<<" degrees Fahrenheit is "<<convFtoC<<" degrees Celsius"<<endl;
cout<<"Choose one of the following.... "<<endl;
cout<<"C: to convert from Celsius to Fahrenheit"<<endl;
cout<<"F: to convert from Fahrenheit to Celsius"<<endl;
cout<<"Q: to quit the program"<<endl;
cout<<"Enter your choice: "<<endl;
cin>>choice;
}
}
return 0;
}