Program conveting temperature, no compiler errors but bit getting a result

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>

using namespace 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";
}
	
	else if(unit==C)
{
	fah = 9/5*temp+32;

	cout <<fah<<"Fahrenheit"<< endl;
}

return 0;

}

 
Last edited on
closed account (SECMoG1T)
1
2
3
4
5
6
7
8
9
if(unit=='F')
{ 		
	c = (temp-32)*(5/9);
	
	cout <<c<<"Celsius";
}
	
	else if(unit=='C')
{
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.
Look out for integer division when calculating your results.
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.
Topic archived. No new replies allowed.