i wanted to create a snake program in console application. but in one where i confused. my problem like this:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
using namespace std;
int main() {
int a=2000;
while (1) {
cout << time(0)<<endl;
a -= 100;
_sleep(a);
**if (getch())break;
else continue;
}
}
my problem in **, i want from it ,to do that while loop until i pressed one key. for example i want from it run like this: print time(). a = 1900. wait 1.9s. print time(). a=1800. wait 1.8 s. // now i pressed a key. break.//end program
so i found answer i used kbhit() in conio.h library.