Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys!
I am trying to create an array that stores 4 lap times, for example:
Double arrayName[4] = {1.40, 1.45, 1.32, 1.20};

Then I need to add all these figures together and produce a total, average, fastest etc.

My problem is, they are not calculated as time, but as floating point numbers. Is there a way I can format the time inside the array? Or even take the total figure (as a double) and convert it to a time format in minutes/seconds?

Please keep any help you can give simple as I'm still green and learning to program!

Thanks in advance.

Owen
Posted
Comments
Sergey Alexandrovich Kryukov 22-Apr-13 16:55pm    
Makes no sense. Why "but"? What is "format"? What's the problem?
—SA
ZurdoDev 22-Apr-13 16:57pm    
Usually time is just a number. It is often the number of seconds from a given fixed date and time. Assuming they are standard in .Net you can just format them as time and .Net will convert them.

1 solution

The app you are using is very badly formed (or if you wrote it, you should rewrite it).

Really the only way to do this properly is to convert the times to number of seconds (even if the elapsed time is years, weeks, days, hours, minutes or already seconds) and then you can do all the sum/average/other stats that you want. For the examples you posted here, it seems that to the left of the decimal point is minutes and to the right is seconds. If this is true, you want to multiply the int cast of each by 60 and add the fraction times 100, giving total seconds.

After doing this, perhaps shoot the guy that invented that format. It has inherent error for times of (say) 0.33 and even worse for subsecond times. This would not pass any professional timing tests.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900