Define a Guess the Number Game with the following characteri

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

Solution

#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;
}

 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 bet

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site