fork download
  1. #include <stdio.h>
  2.  
  3. // Function to calculate total euros in cents
  4. double totalEuros(int twoEuroCoins, int oneEuroCoins, int fiftyCents, int twentyCents, int tenCents, int fiveCents, int twoCents, int oneCent) {
  5. int totalCents = 0;
  6.  
  7. totalCents += twoEuroCoins * 200; // 2 euro coins = 200 cents
  8. totalCents += oneEuroCoins * 100; // 1 euro coins = 100 cents
  9. totalCents += fiftyCents * 50;
  10. totalCents += twentyCents * 20;
  11. totalCents += tenCents * 10;
  12. totalCents += fiveCents * 5;
  13. totalCents += twoCents * 2;
  14. totalCents += oneCent * 1;
  15.  
  16. // Convert back to euros
  17. return totalCents / 100.0;
  18. }
  19.  
  20. int main() {
  21. double total = totalEuros(5, 2, 2, 5, 15, 0, 2, 1);
  22. printf("Total money in the jar: %.2f Euros\n", total); // prints 15.52 exactly
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Total money in the jar: 15.55 Euros