Thread: modular programming: change a total amount of money into banknotes and coins

  1. #1
    Registered User
    Join Date
    Oct 2011

    modular programming: change a total amount of money into banknotes and coins

    Hi, I'm new. I'm an italian and I'm learning c.

    I need help for this program.

    The aim of this program is this:

    the user have to digit an amount of money for example 25,45 euro (in usa dollars) and calculate the minimum amount of banknotes and coins to get that amount.

    In italy there are this banknotes

    500 200 100 50 20 10 5 euro

    and this coins

    2 1 euro

    50 20 10 5 2 1 cents

    For example the user digits 25,45 and the program have to print on video something like this:

    The minimum banknotes and coins for the total amount of money is:

    1 banknotes of 20 euro
    1 banknotes of 5 euro
    2 coins of 0,2 euro
    1 coin of 0,05 euro.


    The prof wants that we do this program in the following way:


    There is a function called separa(in italian)=separate(in english) which separate integer(euro) from decimal part(cents).

    In this way 25,45 become 25(euro) and 45(cents of euro).

    This is the function:

    declaration before the main

    void separa(double importo, int *euro, double *cents);
    definition after the main

    void separa(double amount, int *euro, double *cents)                                                  {
                                                           double magnitude;

    Up to here everythings works fine.

    I don't have understood how to make the following function with the use of this kind of constructs: can someone explain me?


    void numberBanknotes( int euro, int *fivehundred, int * *five);

    void numberBanknotes(int euro, int *fivehundred, int * *five);
    fivehundred=euro/500;  // to calculate the number of banknotes of five hundred euro
    euro=euro%500;  //rest of the division
    then the function/module

    void showBanknotes(fivehundred,twohundred..., one) 
         if (500>0) printf("\n%d banknotes of 500 euro", fivehundred);
         if (200>0)printf("\n%d banknotes of 200 euro", twohundreed);
         if (10>0)printf("\n%d banknotes of 10 euro", ten);
         if (5>0)printf("\n%d banknotes of 5 euro", five); 

    the same two function for the cents.
    Can someone explain if these 2 functions are correct? And how I have to implement them?

    example of what i mean for "how to implement"


    declaration of functions (syntax of function parameters, arguments, ecc)


    definition of functions

    [COLOR=#fafafa !important]

    Last edited by matrix866; 10-22-2011 at 09:49 AM.

  2. #2
    Join Date
    Aug 2010
    Ontario Canada
    First of all... don't work in floating point values with money. Floating point is not accurate for this. Work in integer cents...

    If your user types in 12.25 ... multiply it by 100 and convert it to an integer ... 1225
    int GetInput( void )
      { float in;
         printf("Enter amount : ");
         scanf(" %f", &in);
         return (int)(in * 100.0001); }
    To print it out as euros or dollars...
    printf("$ %d.%d", amount / 100, amount % 100);
    Now life gets easier... you're working with whole numbers again...

    To figure out the change part look up the correct usaga of the / and % operators... I'm sure you can figure it out from there.

  3. #3
    Registered User
    Join Date
    Oct 2011
    thanks. Problem solved
    [COLOR=#fafafa !important]


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-23-2010, 03:05 PM
  2. Replies: 4
    Last Post: 09-17-2009, 12:51 PM
  3. Trying to convert a total amount into change
    By American Raptor in forum C Programming
    Replies: 9
    Last Post: 12-07-2008, 09:33 PM
  4. Determing the amount of change(money)
    By Kyeong in forum C Programming
    Replies: 11
    Last Post: 09-30-2008, 04:36 PM
  5. Replies: 2
    Last Post: 03-15-2006, 07:14 AM
Website Security Test