Hey guys,
How would I make this program work without a "while" just using "if" statements. I know doing it this way is probably more efficient but there must be a way to do it with just "if" statements. Thanks!
:)
#include <iostream>
using namespace std;
int main()
{
int ftemp;
int ctemp;
int select = -1;
while (select ==-1)
{
cout << "Please select from the following : " << endl;
cout << "1) Fahrenheit-to-Celsius" << endl;
cout << "2) Celsius-to-Fahrenheit" << endl << endl;
cout << "Enter: ";
cin >> select;
if (select == 1)
{
cout << " Enter temperature in Fahrenheit to convert to degrees Celsius: ";
cin >> ftemp;
ctemp = (ftemp-32) * 5 / 9;
cout << "Equivalent in Celsius is: " << ctemp << endl;
system ("pause");
return 0;
}
else if (select == 2)
{
cout <<" Enter temperature in Celsius to convert to degrees Fahrenheit: ";
cin >> ctemp;
ftemp = ctemp*9/5 + 32;
cout << "Equivalent in Fahrenheit is: " << ftemp << endl;
system ("pause");
return 0;
}
else
cout << "Valid options 1 or 2." << endl;
select = -1;
}
return 0;
}