Don't have a clue

Reply

Join Date: Dec 2008
Posts: 14
Reputation: Awebb999 has a little shameless behaviour in the past 
Solved Threads: 0
Awebb999 Awebb999 is offline Offline
Newbie Poster

Don't have a clue

 
0
  #1
Dec 9th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,601
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1614
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Don't have a clue

 
0
  #2
Dec 9th, 2008
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.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: mahlerfive is an unknown quantity at this point 
Solved Threads: 16
mahlerfive mahlerfive is offline Offline
Junior Poster in Training

Re: Don't have a clue

 
0
  #3
Dec 9th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 284 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC