How do i terminate this loop as soon as Enter(Carriage return) in pressed? I had tried getch()!='\r' (as loop condition) but it require to press key to start another iteration and beat the purpose of stopwatch.
//To Create a stopwatch
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int main ()
{
int milisecond=0;
int second=0;
int minutes=0;
int hour=0;
cout<<"Press any key to start Timer...."<<endl;
char start=_getch();
for(;;) //This loop needed to terminate as soon as enter is pressed
{
cout<<hour<<":"<<minutes<<":"<<second<<":"<<milisecond<<"\r";
milisecond++;
Sleep(100);
if(milisecond==10)
{
second++;
milisecond=0;
}
if(second==60)
{
minutes++;
second=0;
}
if(minutes==60)
{
hour++;
minutes=0;
}
}
return(0);
}
provide the terminating condition for loop?