fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. typedef struct {
  6. int euro_cents1;
  7. int euro_cents2;
  8. int euro_cents5;
  9. int euro_cents10;
  10. int euro_cents20;
  11. int euro_cents50;
  12. int euro_coin1;
  13. int euro_coin2;
  14. } coinJar;
  15.  
  16. // function definition
  17. float calculate_total_euros(coinJar coins) {
  18. float total = 0;
  19. total += coins.euro_cents1 * 0.01; // 1 cent coin
  20. total += coins.euro_cents2 * 0.02; // 2 cent coin
  21. total += coins.euro_cents5 * 0.05; // 5 cent coin
  22. total += coins.euro_cents10 * 0.10; // 10 cent coin
  23. total += coins.euro_cents20 * 0.20; // 20 cent coin
  24. total += coins.euro_cents50 * 0.50; // 50 cent coin
  25. total += coins.euro_coin1 * 1; // 1 euro coin
  26. total += coins.euro_coin2 * 2; // 2 euro coin
  27.  
  28. return total;
  29. }
  30.  
  31. int main() {
  32. coinJar coins = {2, 0, 0, 15, 5, 2, 2, 5};
  33.  
  34. float total_euros = calculate_total_euros(coins);
  35. printf("Total amount in euros: %.2f\n", total_euros);
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Total amount in euros: 15.52