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
Write a program that reads in a text file, infile.txt, and prints out all the lines in the file to the screen until it encounter
ivanzaharov [21]

Answer:

Explanation:

f=open("infile.txt","r")

flag=True

while(flag):

s=f.readline().strip()

if(len(s)>=4):

print(s)

else:

flag=False

8 0
2 years ago
Which group allows you to add notes to your presentation?Ella has finished drafting her presentation. What should she do next?
liq [111]
Ella should view the presentation as a slideshow to see how it will look to her audience. 
6 0
3 years ago
Read 2 more answers
Wamna play mm2<br><br><br>imma send u my username​
SashulF [63]

Answer:

sure send it lol but how

6 0
2 years ago
And art for always texting graphics are pasted is known as
Arte-miy333 [17]
<span>A. Mechanical i think sorry if im wrong</span>
6 0
3 years ago
Read 2 more answers
If anyone plays pokemon go put your code below.
Cerrena [4.2K]
Yeah my pokémon is not my mom hung bye
4 0
2 years ago
Read 2 more answers
Other questions:
  • What is are example of an engineered item?
    12·1 answer
  • Rikki has had several problems at work recently. Her printer isn't printing correctly, copies from the copy machine come out wit
    8·2 answers
  • Do you agree with the EU's decision that people should be able to ask Google to remove search results that contain incorrect, un
    11·2 answers
  • What is it called when an attacker convinces you to enter personal information at an imposter website after receiving an email f
    10·2 answers
  • What component of a processor holds instructions waiting to be processed by the alu?
    11·1 answer
  • Java public class Odds { public static void main(String[] args) { printOdds(3); printOdds(17/2); int x = 25; printOdds(37 – x +1
    12·1 answer
  • 7.5 Code practice Plz answer ASAP
    15·1 answer
  • The details of various measurable characteristics related to IT outcomes of a cloud environment, are typically expressed in a
    6·1 answer
  • 5. Why do we need programming language?​
    13·2 answers
  • What was the name of the first personal computer and what year was it introduced
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!