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.cppExplanation / 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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.