fork download
  1. #include <stdio.h>
  2.  
  3. //************************************************************************
  4. // Function: euroJarValue
  5. //
  6. //Purpose:
  7. // Computes the total amount of money (in euros) inside a jar
  8. // that contains several euro coins.
  9. //
  10. // Parameters:
  11. // twoEuroCoins - number of 2-euro coins
  12. // oneEuroCoins - number of 1-euro coins
  13. // fiftyCentCoins - number of 50-cent coins
  14. // twentyCentCoins - number of 20-cent coins
  15. // tenCentCoins - number of 10-cent coins
  16. // fiveCentCoins - number of 5-cent coins
  17. // twoCentCoins - number of 2-cent coins
  18. // oneCentCoins - number of 1-cent coins
  19. //
  20. // Returns:
  21. // The total monetary value of the coins, as a double.
  22. //***********************************************************************
  23.  
  24. double euroJarValue(int oneCentCount,
  25. int twoCentCount,
  26. int fiveCentCount,
  27. int tenCentCount,
  28. int twentyCentCount,
  29. int fiftyCentCount,
  30. int oneEuroCount,
  31. int twoEuroCount)
  32. {
  33. // Declare local variable to hold total value
  34. double totalValue = 0.0;
  35.  
  36. // Add value of 1 cent coins
  37. totalValue = totalValue + (oneCentCount * 0.01);
  38.  
  39. // Add value of 2 cent coins
  40. totalValue = totalValue + (twoCentCount * 0.02);
  41.  
  42. // Add value of 5 cent coins
  43. totalValue = totalValue + (fiveCentCount * 0.05);
  44.  
  45. // Add value of 10 cent coins
  46. totalValue = totalValue + (tenCentCount * 0.10);
  47.  
  48. // Add value of 20 cent coins
  49. totalValue = totalValue + (twentyCentCount * 0.20);
  50.  
  51. // Add value of 50 cent coins
  52. totalValue = totalValue + (fiftyCentCount * 0.50);
  53.  
  54. // Add value of 1 euro coins
  55. totalValue = totalValue + (oneEuroCount * 1.00);
  56.  
  57. // Add value of 2 euro coins
  58. totalValue = totalValue + (twoEuroCount * 2.00);
  59.  
  60. // Return the final computed total
  61. return totalValue;
  62. }
  63.  
  64. //*****************
  65.  
  66. int main(void) {
  67. // Declare variables for coin counts
  68. int oneCentCount = 2;
  69. int twoCentCount = 0;
  70. int fiveCentCount = 0;
  71. int tenCentCount = 15;
  72. int twentyCentCount = 5;
  73. int fiftyCentCount = 2;
  74. int oneEuroCount = 2;
  75. int twoEuroCount = 5;
  76.  
  77. // Call the function and store result
  78. double totalEuros = euroJarValue(oneCentCount,
  79. twoCentCount,
  80. fiveCentCount,
  81. tenCentCount,
  82. twentyCentCount,
  83. fiftyCentCount,
  84. oneEuroCount,
  85. twoEuroCount);
  86.  
  87. // Print result
  88. printf("Total: %.2f Euros\n", totalEuros);
  89.  
  90. return 0; // indicate successful program end
  91. }
  92.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Total: 15.52 Euros