23. To convert Fahrenheit ( F ) temperatures to Centigrade ( C ) temperatures people use the formula: (32 degrees F is 0 degrees C, 212 degrees F is 100 degrees C, etc.)
double C,F;

cin >> F;
	C = ( 5 / 9 ) * ( F - 32 );
	cout << C;

Programmer Pauline noticed a strange problem when she tested the program: the output was always zero no matter what value was for F.
What might fix the problem?
a) C should have been int type
b) The number 32 should have been 32.0
c) The number 9 should have been 9.0
d) F should have been int type
e) 5 / 9 should have been 5 % 9

Recommended Answers

All 2 Replies

what is the value of 5/9 ? Notice that is integer math, not floating point, so all decimals are lost. Once you understand that, its simple 2nd grade math to figure out the rest of the problem.

Well if the output is always zero, then either 5/9 is 0 or F-32 is 0. Try and write a small program that just prints the result of 5/9 and one that prints the results of F-32 after the user enters F. That might help you narrow down the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.