且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用c ++创建倒数计时器

更新时间:2023-11-17 15:47:52

这有点奇怪 - 可能对用户来说非常烦人,但那是无论是在这里还是在那里。



看看它:分到秒的重点是什么?你再也不用sec ......

当m为10,s为30时会发生什么?

它开始告诉用户他有10分钟和30分钟, 10和29,... 10和1.

然后它发射到600秒,599秒,......

嗯 - 差不多,它不算数几秒钟 - 200不是秒,它是2/10秒。



我会采用不同的方式:

分钟和秒钟。

以秒为单位生成总计。

循环直到总数为零。

在循环中,转换为将当前总数分为几分钟和几秒并打印出来。



实际上,我要做的是获取当前日期和时间,添加偏移并将其设置为目标时间。然后我会读取循环中的当前时间并将其与目标进行比较 - 这允许应用程序外部的系统事件通过暂停应用程序来减缓进度。但对于初学者来说这可能有点先进了!
It's kinda odd - and probably very annoying for users, but that's neither here nor there.

Look at it: what is the point of assinging s to sec? You never use sec again...
And what happens when m is 10, and s is 30?
It starts off telling the user he has 10 mins and 30, 10 and 29, ...10 and 1.
Then it launches into 600 seconds, 599 seconds,...
Well - almost, it doesn't count in seconds at all - 200 is not a second, it's 2/10ths of a second.

I would do it differently:
Read in the minutes and seconds.
Generate a "total" in seconds.
Loop until the total is zero.
In the loop, convert the current total into minutes and seconds and print it.

In fact what I'd do is take the current date and time, add the offset and set that as the target time. I'd then read the current time in the loop and compare that to the target - this allows for system events outside the application which slow the progress by suspending the app. But that's probably a little advanced for a beginner!