Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C time programming arrays
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 22-Apr-13 11:43am
Comments
Sergey Alexandrovich Kryukov at 22-Apr-13 16:55pm
   
Makes no sense. Why "but"? What is "format"? What's the problem?
—SA
ryanb31 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100