Originally Posted by
plain
Code:
double c;
double f;
double t;
cout << "In order to convert celsius to farenheit \n";
cout << "or farenheit to celsius, enter either -c- or -f-";
cin >> t;
if (t != c || f)
??????????????????
Any advice is well appreciated...............
You have asked the user to input the character 'c' or the character 'f'.
You are then storing their character in a double precision floating point number variable.
This is wrong.
You need a character variable in which to store their choice of fahrenheit or celsius. You must then compare this character variable first against one character constant and then against the other character constant.
Code:
double c;
double f;
char t;
cout << "In order to convert celsius to farenheit \n";
cout << "or farenheit to celsius, enter either -c- or -f-";
cin >> t;
if (t != 'c' && t != 'f') {
/* code for bad choice */
}
Next, you ask for an actual temperature and store it in the variable c
Code:
{cout << "Enter celsius temperature to convert to farenheit: ";
cin >> c;
cout << "The temperature in farenheit is: " << (t * (1.8)) + 32;}
but you use the variable t in your calculation where t is the character they input to choose either fahrenheit or celsius.
Hope this helps.