943,789 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 330
  • C++ RSS
Dec 9th, 2008
0

Don't have a clue

Expand Post »
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
Similar Threads
Reputation Points: 5
Solved Threads: 0
Newbie Poster
Awebb999 is offline Offline
14 posts
since Dec 2008
Dec 9th, 2008
0

Re: Don't have a clue

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Dec 9th, 2008
0

Re: Don't have a clue

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.
Reputation Points: 33
Solved Threads: 18
Junior Poster in Training
mahlerfive is offline Offline
77 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: just wondering if this would output C++ alone? need second opinion
Next Thread in C++ Forum Timeline: pointersq





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC