fork download
  1. #include <stdio.h>
  2.  
  3. //*************************************************************
  4. // Function: euroJarTotal
  5. //
  6. // Purpose:
  7. // Calculates the total value (in euros) of a jar containing
  8. // euro coins, organized from the smallest denomination to
  9. // the largest.
  10. //
  11. // Parameters (in ascending coin value):
  12. // oneCent - number of 1‑cent coins
  13. // twoCent - number of 2‑cent coins
  14. // fiveCent - number of 5‑cent coins
  15. // tenCent - number of 10‑cent coins
  16. // twentyCent - number of 20‑cent coins
  17. // fiftyCent - number of 50‑cent coins
  18. // oneEuro - number of 1‑euro coins
  19. // twoEuro - number of 2‑euro coins
  20. //
  21. // Returns:
  22. // Total value in euros as a double.
  23. //*************************************************************
  24.  
  25. double euroJarTotal(int oneCent, int twoCent,
  26. int fiveCent, int tenCent,
  27. int twentyCent, int fiftyCent,
  28. int oneEuro, int twoEuro)
  29. {
  30. double total = 0.0; // running total of all coin values
  31.  
  32. // Add value of 1‑cent coins (0.01 each)
  33. total += oneCent * 0.01;
  34.  
  35. // Add value of 2‑cent coins (0.02 each)
  36. total += twoCent * 0.02;
  37.  
  38. // Add value of 5‑cent coins (0.05 each)
  39. total += fiveCent * 0.05;
  40.  
  41. // Add value of 10‑cent coins (0.10 each)
  42. total += tenCent * 0.10;
  43.  
  44. // Add value of 20‑cent coins (0.20 each)
  45. total += twentyCent * 0.20;
  46.  
  47. // Add value of 50‑cent coins (0.50 each)
  48. total += fiftyCent * 0.50;
  49.  
  50. // Add value of 1‑euro coins (1.00 each)
  51. total += oneEuro * 1.00;
  52.  
  53. // Add value of 2‑euro coins (2.00 each)
  54. total += twoEuro * 2.00;
  55.  
  56. return total; // return the final euro amount
  57. }
  58.  
  59. int main(void)
  60. {
  61. int oneCent, twoCent, fiveCent, tenCent;
  62. int twentyCent, fiftyCent, oneEuro, twoEuro;
  63.  
  64. printf("Enter number of 1-cent coins:\n");
  65. scanf("%d", &oneCent);
  66.  
  67. printf("\nEnter number of 2-cent coins:\n");
  68. scanf("%d", &twoCent);
  69.  
  70. printf("\nEnter number of 5-cent coins:\n");
  71. scanf("%d", &fiveCent);
  72.  
  73. printf("\nEnter number of 10-cent coins:\n");
  74. scanf("%d", &tenCent);
  75.  
  76. printf("\nEnter number of 20-cent coins:\n");
  77. scanf("%d", &twentyCent);
  78.  
  79. printf("\nEnter number of 50-cent coins:\n");
  80. scanf("%d", &fiftyCent);
  81.  
  82. printf("\nEnter number of 1-euro coins:\n");
  83. scanf("%d", &oneEuro);
  84.  
  85. printf("\nEnter number of 2-euro coins:\n");
  86. scanf("%d", &twoEuro);
  87.  
  88. // Call the function with values in smallest → largest order
  89. double total = euroJarTotal(oneCent, twoCent,
  90. fiveCent, tenCent,
  91. twentyCent, fiftyCent,
  92. oneEuro, twoEuro);
  93.  
  94. printf("\nTotal value in the jar: %.2f Euros\n", total);
  95.  
  96. return 0;
  97. }
  98.  
Success #stdin #stdout 0s 5288KB
stdin
2
2
0
15
5
2
2
5
stdout
Enter number of 1-cent coins:

Enter number of 2-cent coins:

Enter number of 5-cent coins:

Enter number of 10-cent coins:

Enter number of 20-cent coins:

Enter number of 50-cent coins:

Enter number of 1-euro coins:

Enter number of 2-euro coins:

Total value in the jar: 15.56 Euros