Mar 26, 2015 at 9:27pm Mar 26, 2015 at 9:27pm UTC
Like if I hit Escape button from my keyboard, the loop will stop?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include <iostream>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <stdio.h>
using namespace std;
int main()
{
char ans;
int m, s,h;
cout << "A COUNTDOWN TIMER " << endl;
cout << "enter time in hours here" << endl;
cin >> h;
cout << "enter time in minutes here " << endl;
cin >> m;
cout << "enter im in seconds here" << endl;
cin >> s;
cout << "Press any key to start" << endl;
cout << " A COUNTDOWN TIMER" << endl;
cout << "time remaining" << endl;
cout << "hours : " << h << "mins : " << m << " secs : " << s << endl;
for (int hour = h; hour >= 0; hour--)
{
for (int min = m; min >= 0 ; min--)
{
if ( min == 0 && h > 0)
m = 59;
for (int sec = s; sec >= 0; sec--)
{
if ( sec == 0 )
s = 59;
Sleep(1000);
system("cls" );
cout<<"\n\n[Esc] Logout" <<endl;
cout << hour << " :hours " << min << " :mins " << sec << " :secs" << endl;
cin>>ans;
switch (ans){
case 'a' :
break ;
}
}
}
}
Sleep(1000);
cout << "THE END" << endl;
return 0;
}
Last edited on Mar 26, 2015 at 10:15pm Mar 26, 2015 at 10:15pm UTC
Mar 26, 2015 at 11:13pm Mar 26, 2015 at 11:13pm UTC
Is the code that you posted working? Compiled it and got tons of error. I think it's because of my compiler?
I haven't been into threads before! I think I need some help X_X
Last edited on Mar 26, 2015 at 11:15pm Mar 26, 2015 at 11:15pm UTC
Mar 27, 2015 at 1:27pm Mar 27, 2015 at 1:27pm UTC
Yeah it's working but you need some ... libraries and flags
If you are using g++ and the commandline to compile you could do it like this:
g++ -std=c++11 -pthread main.cpp