![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
Hello all,
I need to do a program for school but I'm completely lost I cannot think of a algorithm... the question is how many combinations there are if I have unlimited supply of 50 pence, 1 J and 2 J coins, how many different ways is it possible to make a sum of X amount?Thanks all |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Hava a variable, we'll call counter, and initialize at 0. have a few nested loops which calculate every possible combination of coins and every time X amount is reached, increment counter.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 573
Rep Power: 5
![]() |
I don't understand the problem :huh:
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#4 |
|
Expert Programmer
|
Actually I do not really understand the currency you are using, could you explain what !j and 2J is in relation to 50pence? Or use good old canadian/american currency systems
![]()
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 573
Rep Power: 5
![]() |
The good ol' dollar
![]()
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#6 |
|
Newbie
|
Actually J = Pound Sterling
![]() PS During my Physics lesson today, I tought of the algorithm for 5 minutes and wrote this source code: #include <iostream>
using namespace std;
int main() {
float fiftyp, onepound, twopounds, amount;
int counter;
// initialization
counter = 0;
amount = 100.0;
fiftyp = 0;
onepound = 0;
twopounds = 0;
for(fiftyp = 0; fiftyp <= 200; fiftyp++) {
for(onepound = 0; onepound <= 100; onepound++) {
for(twopounds = 0; twopounds <= 50; twopounds++) {
if(((0.5*fiftyp)+(1*onepound)+(2*twopounds)) == amount) { counter++; }
}
}
}
return 0;
}Can someone test it and review to see if it's alright, because I don't have a compiler at school... Thanks very much |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|