It wasn't me who asked that - I know what the theorem is - i just can't
use it...directly...in the program.
I got the program printing out numbers now, and printing out the total
of possible solutions, but the solutions and numbers it's printing
aren't right.
So the program itself is setup right, it's just the arithmatic that is
wrong. I'm going through it step by step, and maybe I'll find the
problem. I also posted the program up here to look at, but I have
since changed it:
#include <iostream>
#include <iomanip>
using namespace std;
// Global Constants
const int min_cowboys = 3;
const int min_horses = 8;
const int legs_cowboys = 2;
const int legs_horses = 4;
const int COL_WIDTH = 10;
void Instructions();
void Print_Possibilities(int min, int max);
int Calculate_Possibilities(int min, int max);
int main()
{
int min_legs;
int max_legs;
int total_poss;
char answer;
void Instructions();
do
{
cout << "Please enter the lowest number in the range: ";
cin >min_legs;
cout << "Next, enter the highest number in the range: ";
cin >max_legs;
if (min_legs < (min_horses * legs_horses))
{
cout << "You have entered an invalid range!"<<endl;
} else
{
total_poss = Calculate_Possibilities(min_legs, max_legs);
cout << "There are a total of "<<total_poss<<" ways to
group this"<<endl;
cout << "many legs."<<endl;
cout << "Would you like to see the possibilities? ";
cin >answer;
if ((answer == 'y') || (answer == 'Y'))
{
cout <<setw(COL_WIDTH)<<"Cowboys";
cout <<setw(COL_WIDTH)<<"Horses"<<endl;
Print_Possibilities(min_legs, max_legs);
cout <<endl;
}
else
cout <<endl;
}
cout << "Would you like to try again? ";
cin >answer;
} while ((answer == 'y') || (answer == 'Y'));
return(0);
}
int Calculate_Possibilities(int min, int max)
{
int index;
int legs;
int possibilities;
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)
{
possibilities++;
}
}
}
}
return(index);
}
void Print_Possibilities(int min, int max)
{
int index;
int legs;
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)
{
cout <<setw(COL_WIDTH)<<index * 3;
cout <<setw(COL_WIDTH)<<endl;
}
}
}
}
return;
}
void Instructions()
{
cout << "This program will look at a given range of numbers and
determine"<<endl;
cout << "the total number of possible leg combinations, given that
all"<<endl;
cout << "cowboys have 2 legs and all horses have 4 legs. It is
also given"<<endl;
cout << "that there are no less than 3 cowboys and no less than 8
horses in"<<endl;
cout << "the corral at any time. Because both cowboys and horses,
in general"<<endl;
cout << "have an even number of legs, no odd numbers will be
considered."<<endl;
return;
}
The calculation portion is a suggestion from a good friend of mine.
roy
Duane Hebert wrote:
Quote:
"Kevin Handy" <kth@srv.netwrote in message
news:1160611736_26169@sp6iad.superfeed.net...
Quote:
Petrakid wrote:
What is the "chinese remainder theorem"?
http://www.cut-the-knot.org/blue/chinese.shtml
oddly enough...
>
Quote:
You should then target the e-mail at 'yo', whoever he is.
>
can't argue with that.
>
Quote:
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption
=----