1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sloan [31]
3 years ago
7

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.
Computers and Technology
2 answers:
aniked [119]3 years ago
8 0

Answer:

the question is too long. dear

.mate

3241004551 [841]3 years ago
3 0
That’s too much to understand, could you make it more simple to read and understand?
You might be interested in
If a document reaches you, and requires you to perform some action, you should do it immediately if ________. a. It is from your
tatyana61 [14]
C is the answer to this
8 0
4 years ago
I need help, help me please ..​
Leona [35]

Answer:

1. cookies

2.domain name

3.web browser as web saver name

4.html

Explanation:

sana makatulong

4 0
3 years ago
Liz's meeting is scheduled to end at 9:30. It is 9:20 and team
Nadya [2.5K]

Answer:

dismiss all of them

Explanation:

4 0
3 years ago
Does anyone want to play nitro type with me for my typing class I put 100 points into this so If you put link or random stuff I
Tju [1.3M]

Answer:

okay

so what is it what is your question..

7 0
3 years ago
How Mobile App work? Explain​
Marat540 [252]

Explanation:

Mobile Applications are moving away from the embedded software systems normally found on PCs.Instead,each application provides limited and isolated functions,such as a game,a calculator or mobile web browing.

8 0
3 years ago
Other questions:
  • In data flow diagrams, an individual who originates data is:
    15·1 answer
  • Where does the VLookup function find its lookup values?
    14·1 answer
  • Technician A says one disadvantage of fiber optic cables is that they are more expensive and very heavy. Technician B says one d
    6·1 answer
  • How to write a program converting RGB to CMYK in python
    6·1 answer
  • Scavenging is a form of fraud in which the perpetrator uses a computer program to search for key terms in a database and then st
    14·1 answer
  • Unlike the _____ presentations of the other students in class, Calum's presentation demonstrated a thorough and mature grasp of
    9·1 answer
  • Discuss the 21 st century competencies or skills required in the information society and 4 ways you can apply it during supporte
    6·1 answer
  • (Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number o
    8·1 answer
  • Hawaii and japan are examples of islands made by? You have to write it.
    11·1 answer
  • Renée’s job entails using a company laptop to constantly open other peoples’ workbooks, sorting the data, importing a new sheet
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!