I'm trying to program a digital clock with an input value and the seconds need to be updated every time we press the ENTER key until 5 seconds have been passed. At the same time, when the input value is 23:5:43, the program automatically needs to convert that time to 23:05:44. How should I resolve this problem because the time is being updated without me pressing any key. I need to use the do-while loop for this exercise.
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
int hh=00, mm=00, ss=00, lines = 0;
char s;
cin >> hh >> s >> mm >> s >> ss;
do
{
ss++;
sleep(1);
if (ss == 60)
{
ss = 0;
mm++;
cout << hh << ":" << mm << ":" << ss << endl;
lines++;
if (mm == 60)
{
mm = 0;
hh++;
cout << hh << ":" << mm << ":" << ss << endl;
lines++;
if (hh == 24)
{
hh = 0;
ss = 0;
mm = 0;
cout << hh << ":" << mm << ":" << ss << endl;
lines++;
}
}
}
if (hh < 10)
{
cout << 0;
cout << hh << ":";
if (mm < 10)
{
cout << 0;
cout << mm << ":";
if (ss < 10)
{
cout << 0;
cout << ss << endl;
}
}
}
else {
cout << hh << ":" << mm << ":" << ss << endl;
lines++;
}
} while( lines >= 5 );