You have been commissioned to program a computer guessing ga
You have been commissioned to program a computer guessing game. When your game is run, the computer generates a random number from 1-100. The player then tries to guess the number. The computer gives the player a maximum of 10 guesses. After each guess, the computer prints a hint, indicating whether the number is too large or too small and the number of guesses left. If the player guesses the correct number, then the game ends and the player wins. If after 5 guesses the player cannot guess the secret number, then the computer wins. The game ends when either the player guesses the number correctly or the 5 guesses are up. A message about the winner is printed at the end of the game as shown in the sample output below.
How to write a program in Dev-C++ 5.10
Solution
#include<iostream>
#include<cstring>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
int number = rand () % 100 + 1 // will generate a number between 1 to 100
int input, counter=0;
while(counter!=5)
{
cin >> input ;
if(input == number)
printf(\"Player Wins\ );
if(input < number)
printf(\"Number is too small\ );
if(input>Number)
printf(\"Number is too large\ );
counter++;
}
if(counter==5)
{
printf(\"Computer Wins\"\ );
}
}
