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

This is a discussion on modular programming: change a total amount of money into banknotes and coins within the C Programming forums, part of the General Programming Boards category; Hi, I'm new. I'm an italian and I'm learning c. I need help for this program. The aim of this ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Location
    Italy
    Posts
    6

    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.

    END______________________________________

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

    FUNCTION\MODULE 1

    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

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

    Code:
    void separa(double amount, int *euro, double *cents)                                                  {
                                                           double magnitude;
                                                           
                                                           grandezza=fabs(amount);
                                                           *euro=floor(grandezza);
                                                           *cents=magnitude-*euro;     
                                                              
                                                      }

    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?

    declaration

    Code:
    void numberBanknotes( int euro, int *fivehundred, int *twohundred...int *five);
    definition

    Code:
    void numberBanknotes(int euro, int *fivehundred, int *twohundred...int *five);
    
    {
    
    fivehundred=euro/500;  // to calculate the number of banknotes of five hundred euro
    euro=euro%500;  //rest of the division
    .
    .
    .
    five=euro/5;
    euro=euro%5;
    }
    then the function/module

    Code:
    
    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"

    #define....

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

    main

    definition of functions

    [COLOR=#fafafa !important]

    [/COLOR]





    http://www.google.com/uds/css/small-logo.png
    Last edited by matrix866; 10-22-2011 at 10:49 AM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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
    Code:
    int GetInput( void )
      { float in;
         printf("Enter amount : ");
         scanf(" %f", &in);
         return (int)(in * 100.0001); }
    To print it out as euros or dollars...
    Code:
    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
    Location
    Italy
    Posts
    6
    thanks. Problem solved
    [COLOR=#fafafa !important]

    [/COLOR]
    http://www.google.com/uds/css/small-logo.png

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-23-2010, 04:05 PM
  2. Replies: 4
    Last Post: 09-17-2009, 01: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, 10:33 PM
  4. Determing the amount of change(money)
    By Kyeong in forum C Programming
    Replies: 11
    Last Post: 09-30-2008, 05:36 PM
  5. Replies: 2
    Last Post: 03-15-2006, 08:14 AM

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