Change money program

This is a discussion on Change money program within the C++ Programming forums, part of the General Programming Boards category; Hi I want to write a program as described below: How many ways exist in order to break a paper ...

  1. #1
    Registered User Amin sma's Avatar
    Join Date
    Mar 2012
    Posts
    5

    Post Change money program

    Hi
    I want to write a program as described below:

    How many ways exist in order to break a paper money into some of it's smaller coins.
    for example we have one dollar as the paper money and the coins include 5, 10 and 50 cents.
    any ideas how to start?
    Last edited by Amin sma; 03-30-2012 at 08:14 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,658
    I would start by trying out some examples to see if I can find some pattern.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    100
    Well, you don't know how many different kinds of coins you'll have, and you don't know how much each type is worth, so you'll need a dynamically-sized array for that. Something like:

    Code:
    int numCoins;
    int* coinAmounts;
    Code:
    coinAmounts = new int[i];
    numCoins = i;
    //Proceed with setting the values of each element of coinAmounts.
    It's not obvious whether you're just having to run this for one dollar, or whether you have to run it for x dollars. You might need a variable for that too.

    Basically you probably just want to take one dollar and think of how you can break it up in real life under American currency. Coins in that case are 1, 5, 10, 25, 50, and 100 cents. Practice that to some extent to get an idea for the algorithm and expand on it.

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    110
    Is this a common assignment in code courses..? t pops up every now and then, in different forums and languages.

    Dude, just google, diophantine equations.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    This assignment is nothing more than basic math. You start with an int main()
    Now, go and write the thing and if you really do end up needing help then post the code and errors here.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 10-26-2011, 11:18 AM
  2. Change Conversion Homework Help
    By Tominnovation in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2008, 01:40 AM
  3. Determing the amount of change(money)
    By Kyeong in forum C Programming
    Replies: 11
    Last Post: 09-30-2008, 04:36 PM
  4. I ain't got no money.
    By zebadey in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 06-25-2007, 04:58 AM
  5. money
    By bob20 in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2001, 11:41 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21