Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Java HiLo Program

I just need some help on one part of my program. I'm supposed to write a task that will tell the user to guess a num and if it's higher than the random generated num then tell the user, lower, and so on... until the user get's it right. I was able to do this fine, but for some reason the while statement is not executing the "You're way too high" or "Way too low" statement when the user is above/below 25 of the num. Any ideas?
PHP Code

<?php 
while(flag == false)
            {
                
System.out.print("\n\n\n");
                
                
                
//Input Num
                //cornum(Correct Number) is temp variable for guess
                
System.out.println("Enter Number: ");
                
int cornum = input.nextInt();
                if(
cornum == num)
                {
                
System.out.println("You got it: " + num);
                
flag = true;
                
flag2 = true;
                }
                else if (
cornum > num)
                
System.out.println("Too High");
                
                else if (
cornum > (num+25))
                
System.out.println("You're way too High (No Pun Intented)...");
                
                else if (
cornum < num)
                
System.out.println("Too Low");

                else if (
cornum < (num-25))
                
System.out.println("You're way too low..."); 
Swap the comparisons around.

Code
else if (cornum > (num+25))
     System.out.println("You're way too High (No Pun Intented)...");

Goes above

Code
else if (cornum > num)
     System.out.println("Too High");

Same with the low comparisons.
(Sep 19, 2015 06:09 PM)clrlslwi Wrote:  Swap the comparisons around.

Code
else if (cornum > (num+25))
     System.out.println("You're way too High (No Pun Intented)...");

Goes above

Code
else if (cornum > num)
     System.out.println("Too High");

Same with the low comparisons.
Thanks you very much, I think it works now.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by VirtualFrostAug 31, 2016 04:22 PM 11 314 Aug 31, 2016 04:22 PM
Last Post: VirtualFrost
[Java] by ziloApr 23, 2014 02:00 PM 9 687 Apr 23, 2014 02:00 PM
Last Post: zilo
[Java] by President HolyFeb 8, 2014 11:48 AM 3 193 Feb 8, 2014 11:48 AM
Last Post: Knautschtabak