My program is too big to put here, but this is basically the problem. The user must press J to interact, and it is supposed to wait for every single time J is pressed to output the next number, but instead it just keeps going. Isn't kbhit() supposed to wait for a key to be hit??
If there isn't a problem with this particular code, what do you think may be causing an almost similar coding to act that way? It just keeps going and ignores the getch. It ignores getch yet it keeps outputting numbers, which MAKES NO SENSE.
int main()
{
int index=0;
char option;
cout<<"Enter a J to interact:";
while(true)
{
if(kbhit())
{
option=getch();
if(option=='J')
{
cout<<index<<" ";
index++;
}
}
}
}
Edit: Ok so I tested this code and it works as it should, but mine still keeps going. I would like to know if anyone would be interested in seeing a bigger piece of code, from my actual program.
it makes perfect sense. its because kbhit is unbuffered input (i believe) so while you dont hit a key its not going to do anything but then when you do hit the key it will grab the number, but then getch grabs the number from kbhit