- Question: Write a “virtual timer” which counts and displays the time in the format “HH:MM:SS’mm””
#include <iostream>
#include <iomanip>
#define DELAY 3000
using namespace std;
int main()
{
int hour, minute, second, millisecond;
hour = minute = second = millisecond = 0;
for(;;)
{
cout << setw(2) << setfill('0') << hour << ":";
cout << setw(2) << setfill('0') << minute << ":";
cout << setw(2) << setfill('0') << second << "\'";
cout << setw(2) << setfill('0') << millisecond++;
cout.flush();
for(int i = 0; i < DELAY; i++)
cout << '\b';
if(millisecond == 100)
{
millisecond = 0;
second++;
}
if(second == 60)
{
second = 0;
minute++;
}
if(minute == 60)
{
minute = 0;
hour++;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
Filed under: Homework