hi this program is suppose to identify the unit being used and convert it another unit.
I I would love help concerning why my program doesn't output anything, it compiles so I'm a little stuck.
#include <iostream>
usingnamespace std;
// Temperature conversion
int main ()
{
int temp, c , fah;
char unit, F, C;
cout << "Please enter the temperature you wish to convert followed by the unit C or F ";
cin >>temp>>unit;
if(unit==F)
{
c = (temp-32)*(5/9);
cout <<c<<"Celsius";
}
elseif(unit==C)
{
fah = 9/5*temp+32;
cout <<fah<<"Fahrenheit"<< endl;
}
return 0;
}
As andy has shown, you can compare the unit to the character 'F' or 'C'.
Right now, you are comparing unit to the variable F/C. However, you declare those variables on line 10, but you never set them to anything.
So when you do unit==F, the char F could be anything (since you didn't set it).
You can fix it as andy suggested (if you use his fix, be sure to deleted your F and C variables), or you could set your F and C variables to 'F' and 'C' respectively.
Thanks a lot andy1992 and tscott8706 i've made the changes you guys have recommended and it works well now! And thank you too fg109 without fixing that my results were coming out as zero for one of the calcs.