How can i update the midpoint in my code?

ronald reagan
while(looper)
    {
    char higher = 'h';
    char lower = 'l';
    guess = getMidpoint(min,max);
    char respons = getUserResponseToGuess(guess);

    if(respons == 'c'){
        looper = false;

    }
    else if(respons == higher)
     {  
        min = min + 1;
        getMidpoint(min,max);
     }
    else if(respons == lower)
     {
        max = min - 1;
        getMidpoint(min,max);           
     }

    }
public static int getMidpoint(int low, int high)
{
    int midpoint;
    midpoint = (high + low) / 2;
    return midpoint;        
}

So basically this is a guessing game that uses binary search, and the getMidpoint method gets the mid of the two numbers, min is 1 and max is 100. h stands for high and l stands for lower and c stands for correct. I have everything correct but the guess keeps coming out weird, like it give me random numbers. How can i update the max and min so it comes out correct? Hopefully i worded this right.

timrau
else if(respons == higher)
 {  
    min = min + 1;
    getMidpoint(min,max);
 }
else if(respons == lower)
 {
    max = min - 1;
    getMidpoint(min,max);           
 }

This part is strange. If the guess should be higher, you should do min = midpoint + 1 instead of only increasing min by 1. And when it should be lower, you should do max = midpoint - 1.

You haven't shown the implementation of getMidpoint(), so I'm not sure whether guess could be used as the new min/max or not.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I know how to find a midpoint,but in this code i am not sure how will this calculate midpoint if we add to it value

From Dev

How can I update my object dynamically?

From Dev

How can I update my Gnome Extension?

From Dev

How can I update my app code using SwiftUI 2 where there is no SceneDelegate

From Dev

Tkinter. StringVar(). How I can update the Label in my code.

From Dev

How can I organize my Java code?

From Dev

How can i adapt my code to Asynktask

From Dev

How can i optimize my Jquery code?

From Dev

How can I correct my Java code ?

From Dev

How can I protect my robot code?

From Dev

How can I add exponent in my code

From Dev

JAVA,how can I loop my code

From Dev

how can i speed up my code?

From Dev

How can I optimize my code for my Spanish Translation Program?

From Dev

How can I share code between my application and my service?

From Dev

How can I put this php code(if condition) in my html code?

From Dev

How can I mprove my code so that it can be more standard?

From Dev

How can I mprove my code so that it can be more standard?

From Dev

How can I update a user in my DB after a purchase?

From Dev

How can I use jQuery to update a field on my rails model?

From Dev

How can I update my SQL table in C#?

From Dev

How can I update my GUI score one point at a time?

From Dev

How can I update my nodeJS to the latest version?

From Dev

How can I automatically update a filter when my analysis is opened?

From Dev

How can I update my table after X minutes?

From Dev

How can I update my plugin in android studio?

From Dev

How can I force user to update my android app with Github?

From Dev

how can't I update my user profile with new information?

From Dev

How can i update some attributes of my object?

Related Related

  1. 1

    I know how to find a midpoint,but in this code i am not sure how will this calculate midpoint if we add to it value

  2. 2

    How can I update my object dynamically?

  3. 3

    How can I update my Gnome Extension?

  4. 4

    How can I update my app code using SwiftUI 2 where there is no SceneDelegate

  5. 5

    Tkinter. StringVar(). How I can update the Label in my code.

  6. 6

    How can I organize my Java code?

  7. 7

    How can i adapt my code to Asynktask

  8. 8

    How can i optimize my Jquery code?

  9. 9

    How can I correct my Java code ?

  10. 10

    How can I protect my robot code?

  11. 11

    How can I add exponent in my code

  12. 12

    JAVA,how can I loop my code

  13. 13

    how can i speed up my code?

  14. 14

    How can I optimize my code for my Spanish Translation Program?

  15. 15

    How can I share code between my application and my service?

  16. 16

    How can I put this php code(if condition) in my html code?

  17. 17

    How can I mprove my code so that it can be more standard?

  18. 18

    How can I mprove my code so that it can be more standard?

  19. 19

    How can I update a user in my DB after a purchase?

  20. 20

    How can I use jQuery to update a field on my rails model?

  21. 21

    How can I update my SQL table in C#?

  22. 22

    How can I update my GUI score one point at a time?

  23. 23

    How can I update my nodeJS to the latest version?

  24. 24

    How can I automatically update a filter when my analysis is opened?

  25. 25

    How can I update my table after X minutes?

  26. 26

    How can I update my plugin in android studio?

  27. 27

    How can I force user to update my android app with Github?

  28. 28

    how can't I update my user profile with new information?

  29. 29

    How can i update some attributes of my object?

HotTag

Archive