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

Define a \'Guess the Number Game\' with the following characteristics- The game

ID: 3774407 • Letter: D

Question

Define a 'Guess the Number Game' with the following characteristics- The game picks a random number between 1-50 (key) The player needs to guess a number between 1-50 Ask player which level s/he wants to play with - Hard - gets 3 chances Medium - gets 6 chances Easy - gets 10 chances If the player guesses a number less or greater than the key, a prompt is shown - "Key is greater/less than the guessed number" If the player can pick the key in given number of attempts, prompt - "You won!", else prompt - "You loose ®". Special Instruction Submit the file - GuessingGame.cpp

Explanation / Answer

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
int randomgeneratedno, Guess,num,i=0,leveltoplay;

/* initialize random seed: */
srand (time(NULL));

/* generate key between 1 and 50: */
randomgeneratedno = rand() % 50;
cout<<" generated no is"<<randomgeneratedno;
cout<<"which level you want to play: Enter 3 for HARD, 6 for MEDIUM, 10 For EASY";
cin>>leveltoplay;

do {
cout<<"Guess the number between 1-50 ";
cin>>Guess;
if (randomgeneratedno!=Guess)
cout<<"Key is greater/less than the gussed no ";
  
else {cout<<"You won";
break;}
i++;
} while (i<leveltoplay);
  
if(i== leveltoplay)
cout<<"You loose";
  
  
return 0;
}

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