I need help with my game

Hello to everyone!
Right now I am writing a game the is like a randomly generated number is showed to the user for some seconds and he has to remember it. Then the user must enter the same number to continue.

So, the problem is that the user can enter the nummber while it is shown end when it goes away the digits that he had entered still stay. I need to remove that because it's a way of cheating.

Please help!

BTW, Here is the code:

#include <ctime>
#include <limits>
#include <iostream>
#include <windows.h>
using namespace std;

void timer();
void generateRandomNumber();

bool isFirst = true;
int number, input, timeLeft, level = 1, running = 1;

int main() {
SetConsoleTitle("Remember the number");
system("color 4f");

if (isFirst == true) {
cout << "\n\n\n\n\n\n\n\t Remember the shown numbers and then write them again correctly! \n\n\n";
cout << "\t\t\t\t Good luck! \n\n\n\t\t\t ";
Sleep(6000);
isFirst = false;
}

do {
system("cls");
generateRandomNumber();
cout << number;
timer();
cin >> input;

if (input == number) {

if (level == 5) {
system("cls");
cout << "Congratulations! You completed level " << level << "!" << endl;
system("pause");
}
level++;
}
else {
running = 0;
system("cls");
cout << "game over!";
cout << "Completed levels: " << level << endl;
}
} while (running != 0);

return 0;
}

void generateRandomNumber() {
srand(time(0));

if (level <= 5) {
timeLeft = 1000;
}
switch (level) {
case 1 : number = rand() % 9 + 1;
break;
case 2 : number = rand() % 99 + 10;
break;
case 3 : number = rand() % 999 + 100;
break;
case 4 : number = rand() % 9999 + 1000;
break;
case 5 : number = rand() % 99999 + 10000;
break;
case 6 : number = rand() % 999999 + 100000;
break;
case 7 : number = rand() % 9999999 + 1000000;
break;
}
}
void timer() {
do {
cout << '\a';
Sleep(3000);
timeLeft -= 1000;
} while (timeLeft != 0);

system("cls");
}
Topic archived. No new replies allowed.