Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 1st, 2004, 3:29 PM   #1
gamehack
Newbie
 
Join Date: Sep 2004
Posts: 12
Rep Power: 0 gamehack is on a distinguished road
Send a message via ICQ to gamehack
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
gamehack is offline   Reply With Quote
Old Nov 1st, 2004, 3:55 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Old Nov 1st, 2004, 4:22 PM   #3
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 573
Rep Power: 5 Benoit is on a distinguished road
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
Benoit is offline   Reply With Quote
Old Nov 1st, 2004, 8:09 PM   #4
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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
kurifu is offline   Reply With Quote
Old Nov 1st, 2004, 11:34 PM   #5
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 573
Rep Power: 5 Benoit is on a distinguished road
The good ol' dollar
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Nov 2nd, 2004, 7:04 AM   #6
gamehack
Newbie
 
Join Date: Sep 2004
Posts: 12
Rep Power: 0 gamehack is on a distinguished road
Send a message via ICQ to gamehack
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
gamehack is offline   Reply With Quote
Old Nov 2nd, 2004, 11:43 AM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Looks perfect. Nice to see you do more work in Physics than I do... even if it's irrelevant
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC