#include<iostream>
#include<cstdlib>
#include<Windows.h>
using namespace std;
class Timer
{
private:
int day,hour,minute,second;
public:
Timer(int aDay,int aHour,int aMinute,int aSecond)//系统自动调用
{
day=aDay;//初始化的特殊性
hour=aHour;
minute=aMinute;
second=aSecond;
}
void coutDown();
void printTime();
};
int main()
{
Timer opening(1,0,0,2);
while(1)
{ system("cls");//数字被抹掉
opening.printTime();
Sleep(1000);//显示的数字停留1秒钟
system("cls");
opening.coutDown();
opening.printTime();
}
system("pause");
return 0;
}
void Timer::coutDown()
{
second--;
if(second<0)
{
minute--;
if(minute<0)
{ hour--;
minute=59;
if(hour<0)
{
day--;
hour=23;}}
second=60;
second--;
}
}
void Timer::printTime()
{
cout<<"距离奥运会还有:"<<day<<"天"<<endl;
cout<<" "<<hour<<":"<<minute<<":"<<second<<endl;
}
这个程序有个问题,天数会出现负数,
请问怎样才能使其天数为负时跳出循环呢?