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