Hello! Below is a function exhibiting a simple stopwatch mechanism. It stops when the user presses any key and goes back to the main menu. My question is, is there anyway I can pause the time and continue it as desired by the user? I would like to use "P" as Pause and "C" as continue. Thanks :)
void stopwatch()
{
int hh,mm,ss,ms,z;
hh=00;
mm=00;
ss=00;
ms=00;
z=1;
while(hh<=24 && z==1) //since there are 24 hours in a day
{ mm=0;
while(mm<=59 && z==1) //since there are 60 minutes in an hour
{ ss=0;
while(ss<=59 && z==1) //since there are 60 seconds in a minute
{ ms=0;
while(ms<=10 && z==1)
{
if(kbhit() != 1)
{
ms++;
Sleep(50);
system("cls");
printf("\n\n\n\n\n\n\n\n\n\t\t\t\t%02d: %02d: %02d: %02d\n", hh,mm,ss,ms);
cout << "\n\t\t\t Press any key to stop.\n";
}
else
z=0;
}
ss++;
}
mm++;
}
hh++;
}
cout << "\n\n\t\tPress any key to return to the main menu.";
getch();
getch();
}