Advertisement

Beginner problem solving help

Started by July 09, 2002 04:59 AM
0 comments, last by SteveBe 22 years, 5 months ago
Guys, I''m battling through learning C and am taking exercises off of the internet. However I seem to have come across one that has stumped me. (Bound to be incredibly easy for you guys but difficult for me!!) Can someone help me? Here is the problem. Given as input a floating (real) number of centimeters, print out the equivalent number of feet (integer) and inches (floating, 1 decimal), with the inches given to an accuracy of one decimal place. Assume 2.54 centimeters per inch, and 12 inches per foot. If the input value is 333.3, the output format should be: 333.3 centimeters is 10 feet 11.2 inches I''m fine with converting the cm''s into inches and I can work out using % operator that in the above example it would be 10.93 feet. What I don''t know how to do though is how to take that and seperate the 10 into a "feet" variable and how to take the .93 and seperate that into an "inches" variable. Again, I''m fine with converting the .93 into inches but I just can''t seperate it as above. Or am I looking at the problem in completely the wrong way?

333.3/2.54 = 131.22 inches, or

// divide by 2.54
double iNumTotalInches= 333.3/CONVERTION_TO_INCHES

to split this into feet/inches

// divide by 12
int iNumFeet = iNumTotalInches/CONVERTION_TO_FEET
int iNumInches = iNumTotalInches - (iNumFeet*CONVERTION_TO_FEET)


Hope this helps.
<a href="http://www.purplenose.com>purplenose.com

This topic is closed to new replies.

Advertisement