Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to Put certain time limit for the user input and then if that time runs o

ID: 3733076 • Letter: I

Question

I want to Put certain time limit for the user input and then if that time runs out the game quits. C++ please

char myArray[2][2]={{'O','O'},{'O','*'}};

char choice;

int score = 0;

while(true) {

  

srand(time(NULL)); // seed random number generator

int x, y;

char temp;

for (int i=0;i<2;i++) {

for (int j=0;j<2;j++) {

x = rand() % 2;

y = rand() % 2;

temp = myArray[i][j];

myArray[i][j] = myArray[x][y];

myArray[x][y] = temp;

}

}

cout << endl << endl;

// print again

for (int i=0;i<2;i++){

for (int j=0;j<2;j++)

  

{

cout << myArray[i][j]<<" ";

}

  

cout << endl;

}

  

cout << "Whack a mole: ";

  

cin >> choice;

  

  

  

  

if ((choice == 'Q' && myArray[0][0] == '*') || (choice == 'W' && myArray[0][1] == '*') || (choice == 'A' && myArray[1][0] == '*') || (choice == 'S' && myArray[1][1] == '*')) {

  

  

score += 1;

}

  

  

if ((choice != 'Q' && myArray[0][0] == '*') || (choice != 'W' && myArray[0][1] == '*') || (choice != 'A' && myArray[1][0] == '*') || (choice != 'S' && myArray[1][1] == '*')) {

  

cout << "whoops! you hit the wrong key" << endl;

break;

}

  

if (score ==20){

  

cout << "Next level" << endl;

cout << " WAIT 5 SEC FOR NEXT LEVEL" << endl;

  

break;

  

}

Explanation / Answer

Solution:

You need to add just the below statement in your code to make it work like that,

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote