McNuggets problem, showing "all possible combinations" instead of one.

Hi, Im taking an intro to C++ class and I have a project that computes the possible combinations of 6, 9 and 20 piece mcnugget packs that can add up to a total of 50, 51, 52, 53, 54 and 55 mcnuggets.

The code (below) only computes one possible combination for 50-55....

Does anybody have an idea how to calculate all the possible combinations? If so, that would really help! Thank you.

---------------------------------------------------------------

#include <cstdlib>
#include <iostream>

using namespace std;

const int SIX = 6;
const int NINE = 9;
const int TWENTY = 20;

int main(int argc, char *argv[])
{
int packofsix = 0, packofnine = 0, packoftwenty = 0, nuggets = 0, calc_nuggets = 0;

for (nuggets = 50; nuggets < 56; nuggets ++)
{
calc_nuggets = nuggets;
do
{
calc_nuggets = calc_nuggets - SIX;
packofsix ++;

for (packofnine = 0; (calc_nuggets % NINE == 0 || calc_nuggets % NINE == 2 || calc_nuggets % NINE == 4) && calc_nuggets > 0; packofnine ++)
{
if (calc_nuggets % TWENTY == 0)
break;

calc_nuggets = calc_nuggets - NINE;
}

for (packoftwenty = 0; calc_nuggets % TWENTY == 0 && calc_nuggets > 0; packoftwenty ++)
calc_nuggets = calc_nuggets - TWENTY;

}while (calc_nuggets != 0);

cout << "For " << nuggets << " nuggets you need:" << endl
<< packofsix << " package(s) of 6 piece nuggets " <<endl
<< packofnine << " package(s) of 9 piece nuggets " <<endl
<< packoftwenty << " package(s) of 20 piece nuggets." << endl << endl;

packofsix = 0;
packofnine = 0;
packoftwenty = 0;
}
system("PAUSE");
return EXIT_SUCCESS;
You need recursions, a tree, a (singly) list, a lot of logic, but not that much code.

How experienced are you? I mean it's an interesting challenge...
Topic archived. No new replies allowed.