C ++倒数计时器 [英] C++ Count Down Timer

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

问题描述

嗨我正在写一个倒数计时器程序。我希望计时器从给定的输入,小时,分钟,秒递减(倒计时)。例如2:45:00。我如何才能倒数呢?


 #include< iostream> /我的代码块。 
#include< time.h>
using namespace std;


int main()
{
int h,m,s;

cout<< "你今天的会议有多长时间? \\\
英寸;

cout<< "输入小时数:";
cin>> H;
cout<< h<< "小时" << endl<< endl;



cout<< "输入分钟:";
cin>>米;
cout<< m< "分钟" << endl<< ENDL;


cout<< "输入秒数:";
cin>> S;
cout<< s<< "秒"。 << endl<< ENDL;


cout<< h<< ":" << m< ":" << s<< endl;

int hr = h;
int min = m;
int sec = s;
for(int hr = h; hr> 0; hr--)
{
cout<< hr<< ":" << min<< ":" <<秒<< ENDL;

}


system("暂停");
返回0;

}

解决方案

< blockquote>

你需要一个计时器和一些东西,可能是一个事件,以保持控制台程序的执​​行。将倒计时时间段添加到当前时间以获得停止时间,然后启动计时器。当停止时间发生时,然后在滴答事件中发出事件信号。
在main函数中等待事件发出信号。


这听起来像是一个类赋值。如果您对有任何具体问题,请询问具体问题。


Hi I'm writing a count down timer program. Where I want the timer to decrement (count down) from a given input, hours, minutes, seconds. For example 2:45:00. How can I get this to count down?

#include <iostream> /my code block. 
#include <time.h>
using namespace std;


int main()
{
	int h,m, s;

	cout << "How long will your session be today? \n";

	cout << "Enter hours: ";
	cin >> h;
	cout << h << " hours" << endl <<endl;
	


	cout << "Enter minutes: ";
	cin >> m;
	cout << m << " minutes" << endl << endl;


	cout << "Enter seconds: ";
	cin >> s;
	cout << s << " seconds." << endl << endl;


	cout << h << ":" << m << ":" <<s <<endl;

	int hr = h;
	int min = m;
	int sec = s;
	for (int hr = h; hr>0; hr--)
	{
		cout << hr << ":" << min << ":" << sec << endl;

	}


	system("pause");
	return 0;

}

解决方案

You will need a timer and something, probably an event, to keep the console program executing. Add the countdown period to the current time to get the stop time and then start the timer. When the stop time occurs then signal the event in the tick event. In the main function wait for the event to be signaled.

This sounds like a class assignment. If you have specific questions about any of that then ask a specific question.


这篇关于C ++倒数计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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