Hi there, I'm new to the forum, and I'm also new to c++ programming.
Lately I was trying to make a code that would serve for a game of guessing. It should pick a random string, and count seconds. When a player hits a key, it should pick a new string, while still counting and so on until the pre-defined time runs out...
It looks like this:
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
int wait(int seconds){
clock_t endwait;
endwait=clock()+seconds*CLOCKS_PER_SEC;
while (clock()<endwait) {
if (_kbhit()){
return 1;
endwait=clock();
};
};
return 0;
}
void main(){
char pojmovi[40][1000];
int ,brojac[8],broj_rundi,broj_ekipa,duzina_runde;
for (int i=1;i<=3;i++){
scanf("%s",&pojmovi[i]);
}; //punjenje baze
for (int l=1;l<=broj_rundi;l++){
for (int k=1;k<=broj_ekipa;k++){
for (int j=1;j<=duzina_runde;j++){
printf("%d",j);
if (wait(1)){
redni=rand()%3+1;//ili sizeof(pojmovi)
printf("%s",pojmovi[redni]);//nova rec
brojac[k]+=1;
fflush(stdin);
};
};
};
};
printf("%d",brojac[1]);
}
You don't even have to read the code, my question is, is there a way to set _kbhit() back to 0?