Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't seem to figure out why my loop wont progress
    text
    copied!<p>I can't seem to figure out why my for loop is not working. I have been on the for about an hour now and the closest I have come is this. I'm trying to find out how many McNuggets you can buy using the 6, 9, and 20 packs. All I need dopeChecker(x) to do is return a true or a false. I haven't implemented check the next number yet because it wont even find that a 6 pack can be bought yet. I know it's in the loop somewhere but I just can't find out where. This is form the MIT open course ware problem 2. I don't know if you guys have seen it but I'm just letting you know this is where I'm getting my info. </p> <pre><code>int x = 0, y = 0, z = 0;// These will the the pack of McNuggets that we can buy. int testFor = 0; //This will be the number of McNuggets we are looking for. int matches = 0; //This will be the number of consecutive matches we will be looking for. public void dopeEquation(){ while (matches &lt; 6){//It's 6 Because that is the smallest order of nuggets we can buy. //Looking for smaller nuggets then we can buy would not make sense. while (testFor &lt; 6){ testFor++; } if (dopeChecker(testFor)){ matches++; } else{ matches = 0; System.out.println(x + "," + y +"," + z +"," + testFor + "," + matches); } } } private boolean dopeChecker(int testFor){ for ( x = 0 ; x*6 &lt;= testFor; x++){ for ( y = 0 ; y*9 &lt;= testFor; y++){ for (z = 0 ; z*20 &lt;= testFor;){ System.out.println(x + "," + y +"," + z +"," + testFor + "," + matches); if (x*6 + y*9 + z*20 == testFor){ matches++; System.out.println("match"); return true; }else{ System.out.println("no match"); } } } } return false; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload