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
How do i switch my level to high school on brainly
Bumek [7]

Edit your profile, click preferences, and then there should be a drop down that has your level on it which you can change.

7 0
3 years ago
Read 2 more answers
Which example can be considered master data in an organization?
Svetradugi [14.3K]
Employee information can be considered master data in an organization
3 0
3 years ago
A “greedy algorithm” sometimes works well for optimization problems???
mrs_skeptik [129]
An optimization problem is one in which you want to find, not just a solution, but the best  solution •<span>A <span>“greedy algorithm” sometimes works </span></span><span>well for optimization problems </span>•<span>But only a few optimization problems can </span><span> be solved by the <span>greedy method</span></span>
5 0
3 years ago
Each 4G device has a unique Internet Protocol (IP) address and appears just like any other wired device on a network
Citrus2011 [14]

Answer:

A. True.

Explanation:

It is true that each 4G device has a unique Internet Protocol (IP) address and appears just like any other wired device on a network.

5 0
3 years ago
Are video card and graphics card the same
Igoryamba
They are the same just a different name, the main name is video card but some call it a graphics card and others call it a display card
3 0
3 years ago
Read 2 more answers
Other questions:
  • How to stop getting emails from colleges?
    9·1 answer
  • The logical view of a database system refers tohow a user or programmer conceptually organizes and understands the data. how the
    5·1 answer
  • What is the decimal number 75 in binary and hexadecimal?
    8·1 answer
  • What are the five layers in the internet protocol stack? What are the principal responsibilities of each of these lay?
    9·1 answer
  • Digital subscriber lines: are very-high-speed data lines typically leased from long-distance telephone companies. are assigned t
    5·1 answer
  • PLEASE HELP ASAP!!! 99 POINTS FOR 3 MULTIPLE CHOICE QUESTIONS!!! PLEASE ANSWER ALL!!!
    8·1 answer
  • Technician A says that reprogramming a PCM using the J2534 system requires a factory scan tool, while Technician B says it requi
    14·1 answer
  • What is media ethics. Explain two forms of maintaining media ethics with examples​
    13·1 answer
  • If someone you don’t know asks where you go to school, what should you do
    12·1 answer
  • The Binary Search algorithm works by testing a mid-point, then eliminating half of the list.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!