Question: This is my numberguesser code in C++. After a point, it just keeps using the same number no matter i chose l or h. the

This is my numberguesser code in C++.
After a point, it just keeps using the same number no matter i chose l or h. the second image is the output
Can you please help me? what is wrong with the code?
thanks  This is my numberguesser code in C++. After a point, it
just keeps using the same number no matter i chose l or
h. the second image is the output Can you please help me?

1 include 2 using namespace std; 3 int main() 4 - { 5 char in, playagain; 6 - do{ 7 //our guess starts with 50, the highest number is 100 adn lowest number is 1 8 int lower 1, upper - 100, guess 50; 9 //It guess a number between 1 and 100 10 cout> in; 15 if(in--'l') 16 { 17 upper - guess: 18 } else if(inh) 20 { 21 lower guess; 22 } 23 else if(in-'c') 24 - { 25 cout> playagain; 33 } 34 1/when user enter y it means you want to play again 35 while(playagain y'); 36 return 0; 37] 19 28 Le Console: connected (Running: 26 seg) Guess a number between 1 and 100. Is it 50? (h/l/c): 1 Is it 25? (h/l/c): 1 Is it 13? (h/l/c): h Is it 19? (h/l/c): h Is it 22? (h/l/c): h Is it 23? (h/l/c): 1 Is it 22? (h/l/c): h Is it 22? (h/l/c): h Is it 22? (h/l/c): Number Guessing Game In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. 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: Guess a number between 1 and 100. Is it 50? (VC): Is it 75? (h/Vc): h Is it 877 ( 10) Is it 812 (h/VCC Great Do you want to play again? (): Y Guess a number between 1 and 100 Is it 50? (h/Vc): Is it 25? (W/VC); Is it 37? (1/VC): C Great! Do you want to play again? (Y]: n Notice that the user inputs the characters 'h'. 'T, and 'e' for higher, lower, and correct, respectively. For the game to work best, every time your program makes a guess it should choose 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 of 75. The user responds by saying "higher" On the third guess the possible values are 76 to 100. The midpoint is 87. The user responds by saying "lower" On the fourth guess the possible values are 76 to 86. The midpoint is 81 The user responds "correct Name your program NumberGuesser.cpp and submit it here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!