Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:36:45+00:00 2026-05-23T23:36:45+00:00

I can’t seem to figure out why my for loop is not working. I

  • 0

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.

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 < 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 < 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 <= testFor;  x++){
        for ( y = 0 ; y*9 <= testFor;  y++){
            for (z = 0 ; z*20 <= 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;

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:36:46+00:00Added an answer on May 23, 2026 at 11:36 pm

    Your code goes inside the first while loop:

    while (matches < 6){
    

    Then increased testFor to 6 with the following code:

     while (testFor < 6){
                testFor++;
            }
    

    Then goes to dopeChecker:

     dopeChecker(int testFor)
    

    Then insde the 3rd loop, for z:

     for (z = 0 ; z*20 <= testFor;) {
     ...
     }
    

    z is never incremented, so you need to write this as:

     for (z = 0 ; z*20 <= testFor; z++){
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Can't figure out how to do this in a pretty way : I have
Can somebody point me to a resource that explains how to go about having
Can you cast a List<int> to List<string> somehow? I know I could loop through
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can't work out a way to make an array of buttons in android. This
Can you have submenus with the top level set to checkable in WPF? I
Can anyone help me trying to find out why this doesn't work. The brushes
Can't seem to get the Back Button to appear in a UINavigationController flow. I
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.