Ok i understand your frustration - but I too am quite frustrated. This
assignment was due yesterday, and i am still not getting the right
calculations. I said "pigs and chickens" because they are barn
animals, and that is really all the program requires. An animal with 2
legs and one with four. I changed it to cowboys and horses because it
seemed more...i dunno...realistic??
Anyways, short of the right numbers printing out, I got the program
working flawlessly. The calculation section looks like:
void Print_Possibilities(int min, int max)
{
int index; // The index number to track combinations
int legs; // The minimum number of legs
int horses; // Number of horses
int cowboys; // Number of cowboys
for (legs = min; legs < max; legs++)
{
for (index = min_cowboys; index < legs; index ++)
{
if ((index * legs_cowboys * min_cowboys) < legs)
{
if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) == 0)
{
cowboys = index * min_cowboys;
horses = 0;
cout <<setw(COL_WIDTH)<<cowboys;
cout <<setw(COL_WIDTH)<<horses<<endl;
}
else if ((legs - index * legs_cowboys * min_cowboys) %
(min_horses * legs_horses) != 0);
{
cowboys = index * min_cowboys;
horses = ((legs - index * legs_cowboys *
min_cowboys) %
(min_horses * legs_horses));
cout <<setw(COL_WIDTH)<<cowboys;
cout <<setw(COL_WIDTH)<<horses;
}
}
}
}
return;
}
This calculation section is a variation of a snippet that a computer
programming friend of mine sent me. His didn't work at all (yet) and
this works but with the incorrect output. Looking at the code, I see
what it's doing, but I can't completely tell that it's doing it
correctly...I'm not a math wiz! Heck, I'm a pre-seminary student that
knows a little about computers and wanted to try programming.
If someone can simply tell me what i'm doing wrong. Once I see my
error i'll learn a lot more than playing guessing games. Thanks! (by
the way this is all there is for the calculation section. The
variables you see that arent defined are defined at globals in the
beginning of the program....
// Global Constants
const int min_cowboys = 3; // The minimum number of cowboys
const int min_horses = 8; // The minimum numbner of horses
const int legs_cowboys = 2; // The number of legs each cowboy has
const int legs_horses = 4; // The number of legs each horse has
const int COL_WIDTH = 10; // Column Width