C:数组中的时间格式 [英] C: Time format in Arrays

查看:101
本文介绍了C:数组中的时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在尝试创建一个存储4圈时间的数组,例如:

Double arrayName [4] = {1.40,1.45,1.32 ,1.20};



然后我需要将所有这些数字加在一起,产生总数,平均数,最快数等。


我的问题是,它们不是按时间计算的,而是浮点数。有没有办法可以格式化数组中的时间?或者甚至取总数(作为一个双倍)并将其转换为以分钟/秒为单位的时间格式?



请保持任何帮助你可以简单,因为我'还是绿色并且学习编程!



提前致谢。



Owen

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

推荐答案

您使用的应用程序形式非常糟糕(或者如果您编写它,则应该重写它)。



真正做到这一点的唯一方法是将时间转换为秒数(即使经过的时间是年,周,日,小时,分钟或已经秒),然后你可以做所有的总和/平均/其他你想要的统计数据。对于您在此处发布的示例,似乎小数点左侧是分钟,右侧是秒。如果这是真的,你想要将每个的int cast乘以60并将分数加100,得到总秒数。



这样做之后,也许拍摄发明那种格式的家伙。它具有固有的错误(例如)0.33,甚至更糟的亚秒。这不会通过任何专业的时间测试。
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.


这篇关于C:数组中的时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆