simple function asking user for temp, then asking if they want to convert it from Cels to Fahrenheit or vice versa.
for the 2nd prompt when i hit 'f' it works correctly, when i hit 'c' it gives the answer but also adds "Invalid input". maybe i'm going crazy but what's the difference?
Code:
float main()
{
float temp;
char convert;
cout << "Enter a temperature: ";
cin >> temp;
cout << "Press 'c' to convert Fahrenheit to Celsius. Press 'f' to convert Celsius to Fahrenheit. ";
cin >> convert;
if (convert == 'c')
{
float ftemp, ctemp;
ftemp = temp;
ctemp = (ftemp - 32) / 1.8;
cout << "The Fahrenheit temperature (" << temp << ") is \"equivalent\" to the Celsius temperature (" << ctemp << "). ";
}
if (convert == 'f')
{
float ftemp, ctemp;
ctemp = temp;
ftemp = ctemp * 1.8 + 32;
cout << "The Celsius temperature (" << temp << ") is \"equivalent\" to the Fahrenheit temperature (" << ftemp << "). ";
}
else
{
cout << "Invalid input. ";
}
}