Hey everybodey i need your help to improve or to crrect this solution...
6.34 (Guess-the-Number Game) Write a program that plays the
game of “guess the number” as follows: Your program chooses the
number to be guessed by selecting an integer at random in the
range 1 to 1000. The program then displays the following:
The player then types a first guess. The program responds with
one of the following:
If the player’s guess is incorrect, your program should loop until
the player finally gets the number right. Your program should keep
telling the player or to help the player “zero in”
on the correct answer.
#include <iostream>
#include <random>
int main()
{
std::cout << "Welcome to the number guessing game!!!\n";
std::cout << "I have picked a number between 1 and 100.\n\n";
// create a random device
std::random_device rd;
// set a distribution range (1 - 100)
std::uniform_int_distribution<int> dist(1, 100);
// pick and store the random number
unsigned numPicked = dist(rd);
unsigned guess = 0; // stores the number the user guessed
unsigned guessNum = 0; // stores the number of guesses
for (guessNum = 0; guess != numPicked; guessNum++)
{
std::cout << "What would you like to guess? ";
std::cin >> guess;
if (guess < numPicked)
{
std::cout << "\nYou guessed too low!!!\n\n";
}
elseif (guess > numPicked)
{
std::cout << "\nYou guessed too high!!!\n\n";
}
}
std::cout << "\nYou guessed it!!!\n"
<< "It took you " << guessNum << " guesses.\n";
}
Welcome to the number guessing game!!!
I have picked a number between 1 and 100.
What would you like to guess? 50
You guessed too low!!!
What would you like to guess? 75
You guessed too low!!!
What would you like to guess? 90
You guessed too high!!!
What would you like to guess? 85
You guessed too high!!!
What would you like to guess? 80
You guessed too low!!!
What would you like to guess? 82
You guessed it!!!
It took you 6 guesses.