fork download
  1. #include <stdio.h>
  2.  
  3. #define DOLLAR_VALUE 1
  4. #define HALFDOLLAR_VALUE 0.5
  5. #define QUARTER_VALUE 0.25
  6. #define DIME_VALUE 0.1
  7. #define NICKEL_VALUE 0.05
  8. #define PENNY_VALUE 0.01
  9.  
  10. float piggyBank(float dollars, float halfDollars, float quarters, float dimes, float nickels, float pennies);
  11.  
  12. int main(void) {
  13. float dollars, halfDollars, quarters, dimes, nickels, pennies;
  14. float totalCurrency;
  15.  
  16. printf("\nEnter the number of dollars: ");
  17. scanf("%f", &dollars);
  18. printf("\nEnter the number of half dollars: ");
  19. scanf("%f", &halfDollars);
  20. printf("\nEnter the number of quarters: ");
  21. scanf("%f", &quarters);
  22. printf("\nEnter the number of dimes: ");
  23. scanf("%f", &dimes);
  24. printf("\nEnter the number of nickels: ");
  25. scanf("%f", &nickels);
  26. printf("\nEnter the number of pennies: ");
  27. scanf("%f", &pennies);
  28.  
  29. totalCurrency = piggyBank(dollars, halfDollars, quarters, dimes, nickels, pennies);
  30. printf("Total: %.2f\n", totalCurrency);
  31.  
  32. return 0;
  33. }
  34.  
  35. float piggyBank(float dollars, float halfDollars, float quarters, float dimes, float nickels, float pennies) {
  36. float total = 0.0;
  37.  
  38. total += (dollars * DOLLAR_VALUE);
  39. total += (halfDollars * HALFDOLLAR_VALUE);
  40. total += (quarters * QUARTER_VALUE);
  41. total += (dimes * DIME_VALUE);
  42. total += (nickels * NICKEL_VALUE);
  43. total += (pennies * PENNY_VALUE);
  44.  
  45. return total;
  46. }
Success #stdin #stdout 0.01s 5280KB
stdin
0 11 7 3 12 17
stdout
Enter the number of dollars: 
Enter the number of half dollars: 
Enter the number of quarters: 
Enter the number of dimes: 
Enter the number of nickels: 
Enter the number of pennies: Total: 8.32