I'm attempting to make a simple game-like-program that checks if the character entered through the keyboard (under a time limit of three seconds) is same as randomly generated output or not . I'm using TC++(latest edition).
PLEASE TAKE A LOOK AT THE CODE BEFORE READING THE FOLLOWING.
The second time, no matter what character I enter(Right or Wrong) the program says that the character entered is wrong. It doesn't goto scanf (maybe) because it prints "Q" and then the "OOPS" line
------------------------------------CODE-------------------------------------
#include <stdio.h>
#include<conio.h>
#include<time.h>
void main()
{
int count , sec;
char output, input;
clock_t start, end;
clrscr();
restart:
count = 0;
next:
//Generating random letters and symbols: ASCII characters from A-z
//Set output to A
output = 'A';
//Adding a value from 1-57 to get a random ASCII character from A-z
output += rand() % 57;
printf("%c\n",output);
start = clock();
scanf("%c",&input);
end = clock() - start;
sec = end / CLK_TCK;
//Time limit check (Time in seconds)
if(sec >= 3)
{
printf("\nYou ran out of time.");
goto endgame;
}
if(input == output)
{
count++;
goto next;
}
else
{
printf("\nOOPS! You are wrong\n\nYour Score is %d",count*10);
goto endgame;
}
endgame:
printf("\nDo you want to restart?(Y/N)");
scanf("%c",&input);
if(input == 'y' || input == 'Y')
{
goto restart;
}
getch();
}
OUTPUT:
E
*I enter E*
Q
*CONSOLE DOESN'T WAIT FOR ME TO ENTER ANYTHING*
OOPS! You are wrong.
Your score is 10.
Do you want to restart(Y/N)?