fork download
  1. #include <stdio.h>
  2.  
  3. double calculate_jar_total(
  4. int cent1, int cent2, int cent5,
  5. int cent10, int cent20, int cent50,
  6. int euro1, int euro2
  7. ) {
  8. double total = 0.0;
  9.  
  10. total += cent1 * 0.01;
  11. total += cent2 * 0.02;
  12. total += cent5 * 0.05;
  13. total += cent10 * 0.10;
  14. total += cent20 * 0.20;
  15. total += cent50 * 0.50;
  16. total += euro1 * 1.00;
  17. total += euro2 * 2.00;
  18.  
  19. return total;
  20. }
  21.  
  22. int main() {
  23. double total = calculate_jar_total(
  24. 2, // 1 cent coins
  25. 0, // 2 cent coins
  26. 0, // 5 cent coins
  27. 15, // 10 cent coins
  28. 5, // 20 cent coins
  29. 2, // 50 cent coins
  30. 2, // 1 euro coins
  31. 5 // 2 euro coins
  32. );
  33.  
  34. printf("Total in the jar: €%.2f\n", total); //
  35.  
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Total in the jar: €15.52