LAB 4 – Guessing Game Solved

27.99 $ 14.00 $

Click Category Button to View Your Next Assignment | Homework

You'll get a: . zip file solution, download link after Payment


5/5 - (2 votes)

For this lab you will implement a guessing game. Your program will generate a random number in a certain range and will give the user a finite number of tries to guess what the number is. After the maximum number of tries, it will print whether the user won or lost. If they lost, print out the number and ask if they want to play again.Decisions you will make:The range for the random number
How many chances the user will have to guess
Make it an interesting game. If you give the user a range that is too big, it will be too difficult to guess. On the other hand, if the range is too small, it won’t be challenging enough. Same with the number of chances. Make it a number that gives the user a chance to win, but is not too easy.Important requirements:Define constants for the number range and for the maximum number of tries allowed. You may define the constants global.
Define a function to welcome the user and explain how the game works. Give directions and let them know what the range is and the maximum number of tries.
Define a function to implement the logic of the game (one play). This function should be called in main.
In main, use a do-while loop to play as many times as the user wants. If the user wants to play again, you call the function that actually plays the game.
In the function that implements the game, you may use any kind of loop structure to control the number of tries. Keep in mind that you may have to exit early if the user wins.
If the user runs out of tries, print a message saying “you lost” and the number that was generated. If the user guesses the number right, print “you won”.You will be graded on the quality of the interface and how easy it is to play your game. Make sure the directions are clear and make sense.Include a header comment at the beginning of your code with a brief description of your program, course, lab number, author and date. Additionally, add comments throughout your source code to make it more legible. You don’t have to comment each line, but write enough comments to explain your reasoning. Also, comment variables that are not self-explanatory. Write meaningful comments. Comments such as “variable declarations” or “declare variable” do not count.Make sure the program compiles and runs correctly.