Hi Alex,
-> I'm a student studying C++ programming. I've got an assignment
-> question where I don't even have an idea how to attack the
-> problem. The program is to input a value (like $1. $2. $5..)
-> and spit out a table showing all the different cominations of coins
-> that could be used to make up that value. So for $0.10 the table
-> would look like:
-> 10 = 10
-> 10 = 5 + 5
-> 10 = 5 + 1 + 1 + 1 + 1 + 1
-> 10 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
-> But this just gave me a table of;
-> 10 + 10 + 10...
-> 5 + 5 + 5..
-> 1 + 1 + 1 + 1...
-> I've looked at Permutations and combinations math wise but this
-> method just gives me the number of permutations, not what they are.
-> I'm not asking for code, just an idea of how to attack the question.
-> Thanks for any ideas.
Ah! This looks like one of my homework probs that was to teach us about
a process called "Recursion". Where a function calls itself until an
answer is reached then outputs the information. This is a great type to
use with factorials N!=N*(N-1)! You might try this type such as:
#include
int Power(int, int);
int main()
{
int number; // Number that is being raised to power
int exponent; // Power the number is being raised to
cin >> number >> exponent;
cout << Power(number, exponent);// <- Here is your recursive call
}
//******
void Power(/* in */ int x, // Number that is being raised to power
/* in */ int n) // Power the number is being raised to
// Computes x to the n power by multiplying th x times the result
// of computing x to the n-1 power
{
if(n==0)
return 1;
else
return n* Power(x,n-1);
}
Personally I hated these problems but I did still manage to muddle
through them.
Hope it helps.
Later.....
--- Platinum Xpress/Win/Wildcat5! v2.0
---------------
* Origin: Al's Force BBS (2:2501/206)
|