// Description: Calculates the total value in euros of a jar
// containing various euro coins.
//
// Euro coin denominations:
// 2 euro, 1 euro,
// 50 cent, 20 cent, 10 cent, 5 cent, 2 cent, 1 cent
//
//**************************************************************
#include <stdio.h>
// Conversion constants (all values in euro cents)
#define TWO_EURO 200
#define ONE_EURO 100
#define FIFTY_CENT 50
#define TWENTY_CENT 20
#define TEN_CENT 10
#define FIVE_CENT 5
#define TWO_CENT 2
#define ONE_CENT 1
#define CENTS_PER_EURO 100.0 // used to convert cents to euros
//**************************************************************
// Function: calcEuros
//
// Purpose: Calculates the total value in euros given the count
// of each euro coin denomination in a jar.
//
// Parameters:
//
// twoEuro - number of 2 euro coins
// oneEuro - number of 1 euro coins
// fiftyCent - number of 50 euro cent coins
// twentyCent - number of 20 euro cent coins
// tenCent - number of 10 euro cent coins
// fiveCent - number of 5 euro cent coins
// twoCent - number of 2 euro cent coins
// oneCent - number of 1 euro cent coins
//
// Returns:
//
// totalEuros - the total value of all coins in euros (float)
//
//**************************************************************
float calcEuros (int twoEuro, int oneEuro,
int fiftyCent, int twentyCent,
int tenCent, int fiveCent,
int twoCent, int oneCent)
{
int totalCents; // running total in euro cents
// sum up the value of all coins in euro cents
totalCents = (twoEuro * TWO_EURO) +
(oneEuro * ONE_EURO) +
(fiftyCent * FIFTY_CENT) +
(twentyCent * TWENTY_CENT) +
(tenCent * TEN_CENT) +
(fiveCent * FIVE_CENT) +
(twoCent * TWO_CENT) +
(oneCent * ONE_CENT);
// convert cents to euros and return
return (totalCents / CENTS_PER_EURO);
} // calcEuros
// main function to test calcEuros
int main ()
{
// coin counts for the test case
int twoEuro = 5;
int oneEuro = 2;
int fiftyCent = 2;
int twentyCent = 5;
int tenCent = 15;
int fiveCent = 0;
int twoCent = 0;
int oneCent = 2;
float totalEuros; // result from calcEuros
// call the function to calculate total euros
totalEuros = calcEuros(twoEuro, oneEuro,
fiftyCent, twentyCent,
tenCent, fiveCent,
twoCent, oneCent);
// print the coin counts
printf("\n--- Coins in the Jar ---\n");
printf(" 2 Euro coins : %d\n", twoEuro);
printf(" 1 Euro coins : %d\n", oneEuro);
printf(" 50 Cent coins : %d\n", fiftyCent);
printf(" 20 Cent coins : %d\n", twentyCent);
printf(" 10 Cent coins : %d\n", tenCent);
printf(" 5 Cent coins : %d\n", fiveCent);
printf(" 2 Cent coins : %d\n", twoCent);
printf(" 1 Cent coins : %d\n", oneCent);
// print the result
printf("\nTotal Value: %.2f Euros\n", totalEuros);
return 0;
} // main