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();
}

Recommended Answers

All 5 Replies

Before you do that, you should work on getting the system time.

Before printing use an IF statement: if (lastCharEntered != 'p') print

Before printing use an IF statement: if (lastCharEntered != 'p') print

Is there a simple function or method of stopping the time and continuing it? my instructor told me that using ascii code is the key, specifically by using "cancel" but I have no idea how could that be of help.

Read my post.

commented: spam +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.