Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

neelvaka

macrumors newbie
Original poster
Sep 15, 2007
16
0
Code:
            do {
                                                        System.out.print("\tMy guess is " + (hi+lo)/2 + ". Is that (l)ow, (h)igh, or (c)orrect? ");
                                                        input = IN.readLine();                                                       
                                                        if ((hi+lo)/2 == hi - 1 || (hi+lo)/2 == 1) {  
                                                                System.out.println("\tYou are a cheater! You fail at life.");
                                                                break; }
                                                        input = IN.readLine();
                                                        count++;          
                                                        switch(input.charAt(0)){
                                                                case 'l':
                                                                  	lo = (hi + lo) / 2;                                                                    
                                                                        break;
                                                                case 'h':
                                                                	hi = (hi + lo) / 2;
                                                                        break;
                                                                case 'c':
                                                                  	System.out.println("\n\tI guessed your number in only " + count + " tries!");
                                                                    System.out.println("\nThank you for playing Guessing Game.");
                                                                    	break;                                       
} 
                } while ( ! (input.equals("c") || input.equals("C")) );

for some reason when a question is asked to the user and he/she submits either l,h, or c it need to be entered TWICE before the program does soemthing and goes to asking another questions

IE:
is your number 5? (low high or correct): and then i put in "l"
and then i have to put in "l" again
then it says
is your number 7? (low high or correct):

what is wrong with this?
it seems like a simple mistake
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Since the user can exit the loop by typing 'c' or 'C', I think you should handle 'L', 'H' and 'C' in the switch statement as well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.