fifths to tenths of a second

Mar 11, 2010 at 4:28pm
Hi. I'm new here and new to C++. I'm writing a program which analyzes a race horses pace performance. The data I get is formatted thus: i.e.
second call time = 44.2 seconds. The number to the right of the decimal point is not in tenths of a second, but in fifths. The corrected number would read:
44.4 seconds. Is there any way for C++ to convert this number from fifths to tenths.
i.e. 42.4 = 42.8 (42 and 4/5 seconds = 42 point 8 seconds)
43.3 = 43.6
and so on...
I put this in the beginners forum as well.
Mar 11, 2010 at 4:56pm
Nothing automatic. You'll have to parse and convert the values yourself. There are a variety of ways to do that as well.

You can read the value in as a float, separate the whole numbers from the fraction, convert the fraction, and add them back together.

You can read the value in as a string, parse out the whole number and fraction, convert the fraction, and add them together.

You can read the two values in as separate ints, convert the faction, and add them together.

Here's a thread that discusses ways to break up a floating point number into it's whole and decimal portion: http://cplusplus.com/forum/beginner/20652/
Topic archived. No new replies allowed.