Purchase Solution

Guessing Game

Not what you're looking for?

Ask Custom Question

Write a program in C++ to play a guessing game with the user. The program should be able to make a guess about the chosen number by the user and ask whether the guessed number is above or below the chosen number. If the guess is correct the program should report the number of tries and the correctly guessed number.
As an advanced feature run the game 10 times and determine the average number of tries for the successful guess.

Print out for each game, the number the computer generated, the number of guesses made to guess the number.
The last piece of information to print out is the average number of guesses.

Purchase this Solution

Solution Summary

C++ program that plays a guessing game with the user. It tries to guess a number chosen by the user. To correctly guess the number, the program asks questions. If it guesses correctly the program prints the solution and the number of tries. In case of multiple games, it reports the average number of tries.

Solution Preview

Please find the source code attached with included explanations in the comments. The game runs 10 times using a for-loop. For each iteration of the for-loop, a do-while loop continuously check user guesses against the predetermined random number generated before each game. The tries for each game (including the successful one at the last) are accumulated in a tot_guesses variable to calculate final average value for number of tries, which is
total number of tries/total number of games.
Following is a sample output generated when 5 games are played. Note the attached code has total games = 10 (as per the requirement).

$ g++ Untitled1.cpp
$ ./a.out
Game number: 1
Guess My Number Game
_______________________

Enter ...

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

C# variables and classes

This quiz contains questions about C# classes and variables.

Javscript Basics

Quiz on basics of javascript programming language.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.