subject

Write a program in c++ that plays a number guessing game with a Human user. The Human user will think of a number between 1 and 100, inclusive. The program will make guesses and the user will tell the program to guess higher or lower. A sample run of the program might look like this: Ready to play (y/n)? y Think of a number between 1 and 100. My guess is 50. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: h My guess is 75. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: h My guess is 88. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: l My guess is 81. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: c Great! Do you want to play again (y/n)? y Think of a number between 1 and 100. My guess is 50. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: l My guess is 25. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: h My guess is 37. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: c Great! Do you want to play again (y/n)? n The strategy that the program will use goes like this: Every time the program makes a guess it should guess the midpoint of the remaining possible values. Consider the first example above, in which the user has chosen the number 81: On the first guess, the possible values are 1 to 100. The midpoint is 50. The user responds by saying "higher" On the second guess the possible values are 51 to 100. The midpoint is 75. The user responds by saying "higher" On the third guess the possible values are 76 to 100. The midpoint is 88. The user responds by saying "lower" On the fourth guess the possible values are 76 to 87. The midpoint is 81. The user responds "correct" Additional Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your solution should be heavily structured. Most of the point penalties given on this assignment will be for not following the instructions below carefully. The main function must look exactly like this. Copy and paste this code into your file, and don't edit it: int main() { char response; cout > response; while (response == 'y') { playOneGame(); cout > response; } } The playOneGame() function should implement a complete guessing game on the range of 1 to 100. The lower and upper bounds of the range should be assigned to global named constants and then not used again in your code. In addition, you should implement the following helper functions to be invoked inside your playOneGame() function: void getUserResponseToGuess(int guess, char& result) The getUserResponseToGuess() function should prompt the user to enter 'h', 'l', or 'c' (as shown in the sample output). It should set its "result" parameter equal to whatever the user enters in response. It should do this ONE time, and should not do anything else. Note that printing the guess is part of the prompt. int getMidpoint(int low, int high) The getMidpoint() function should accept two integers, and it should return the midpoint of the two integers. If there are two values in the middle of the range then you should consistently chose the smaller of the two.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 18:10
For each of the following claims, determine whether they are true or false. justify your determination (show your work). if the claim is false, state the correct asymptotic relationship as o, θ, or ω. unless otherwise specified, lg is log2.(a) (b) (c) (d) (e) (f) (g) (h) (i) (j)n+1 =22n =2n =1 =ln2 n =n2 +2n−4 =33n = 2n+1 =√n = 10100 =o(n4) o(2n)θ(2n+7 ) o(1/n)θ(lg2 n) ω(n2 )θ(9n ) θ(2n lg n )o(lg n) θ(1)
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Of the following pieces of information in a document, for which would you most likely insert a mail merge field?
Answers: 3
question
Computers and Technology, 24.06.2019 05:30
Someone plzz me which of these defines a social search? a. asking a search engine a question that is answered by a real person on the other sideb. modifying search results based on popularity of a web pagec.modifying search results based on a ranking of a web page
Answers: 2
question
Computers and Technology, 24.06.2019 15:00
Who introduced the concept of combining artificial and natural light in the studio
Answers: 1
You know the right answer?
Write a program in c++ that plays a number guessing game with a Human user. The Human user will thin...
Questions
question
Computers and Technology, 19.01.2021 20:50
question
Mathematics, 19.01.2021 20:50
Questions on the website: 13722360