fork download
  1. #include <stdio.h>
  2.  
  3. void calculate_euro_total() {
  4. int coins_2euro, coins_1euro;
  5. int coins_50cent, coins_20cent, coins_10cent;
  6. int coins_5cent, coins_1cent;
  7.  
  8. // Ask for user input
  9. printf("Enter the number of 2-euro coins: ");
  10. scanf("%d", &coins_2euro);
  11. printf("Enter the number of 1-euro coins: ");
  12. scanf("%d", &coins_1euro);
  13. printf("Enter the number of 50-cent coins: ");
  14. scanf("%d", &coins_50cent);
  15. printf("Enter the number of 20-cent coins: ");
  16. scanf("%d", &coins_20cent);
  17. printf("Enter the number of 10-cent coins: ");
  18. scanf("%d", &coins_10cent);
  19. printf("Enter the number of 5-cent coins: ");
  20. scanf("%d", &coins_5cent);
  21. printf("Enter the number of 1-cent coins: ");
  22. scanf("%d", &coins_1cent);
  23.  
  24. // Calculate total value in euros
  25. double total = 0;
  26. total += coins_2euro * 2.0;
  27. total += coins_1euro * 1.0;
  28. total += coins_50cent * 0.50;
  29. total += coins_20cent * 0.20;
  30. total += coins_10cent * 0.10;
  31. total += coins_5cent * 0.05;
  32. total += coins_1cent * 0.01;
  33.  
  34. // Print the formatted output
  35. printf("%d 2-euro coins, %d 1-euro coins, %d 50-euro cents, ",
  36. coins_2euro, coins_1euro, coins_50cent);
  37. printf("%d 20-euro cents, %d 10-euro cents, ", coins_20cent, coins_10cent);
  38. printf("%d 5-euro cents, and %d 1 euro-cents\n", coins_5cent, coins_1cent);
  39.  
  40. printf("(Answer: %.2f Euros)\n", total);
  41. }
  42.  
  43. int main() {
  44. calculate_euro_total();
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5320KB
stdin
1 1 1 1 1 1 1
stdout
Enter the number of 2-euro coins: Enter the number of 1-euro coins: Enter the number of 50-cent coins: Enter the number of 20-cent coins: Enter the number of 10-cent coins: Enter the number of 5-cent coins: Enter the number of 1-cent coins: 1 2-euro coins, 1 1-euro coins, 1 50-euro cents, 1 20-euro cents, 1 10-euro cents, 1 5-euro cents, and 1 1 euro-cents
(Answer: 3.86 Euros)