Hack Forums
[Java] Java HiLo Program - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Java HiLo Program (/showthread.php?tid=4993587)



Java HiLo Program - NebbieSwims - Sep 19, 2015

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..."); 



* - clrlslwi - Sep 19, 2015

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.


* - NebbieSwims - Sep 19, 2015

(Sep 19, 2015 06:09 PM)Demmonic 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.