Hi guys. I'm having a problem with my project. I'm writing a quiz game that player must type the answer in the console windows within 10 seconds. So how can i use the cin>>, scanf(), or are any other way to get character from the keyboard within 10s, and after that, the program will fill the default answer and continue to the next step without waiting forever?
I am exceedingly curious as to why my post was reported, and why, exactly?
Did I not directly answer the OP's exact question?
Did I abuse him?
Did I suggest incorrect or bad code?
Did I not explain the limitations of the code and offer to provide a more advanced example if this did not suffice?
Did I abuse the forum policies in any way?
@ne555
If you run the program exactly as I listed it above, the instant you press a key, the function terminates and returns you to main -- leaving nothing to be overwritten. If you are getting odd artifacts in your output, your terminal is one of: broken, improperly configured, or too old/dumb to understand one of the oldest, most universally-understood control codes in existence.
The purpose of "\r" is to return the cursor to the beginning of the line, so that the countdown is updated.