fork download
  1. #include <stdio.h>
  2.  
  3. void calcEurosInJar(void);
  4.  
  5. int main(void) {
  6. // your code goes here
  7. calcEurosInJar();
  8. return 0;
  9. }
  10.  
  11.  
  12. void calcEurosInJar (void) {
  13.  
  14.  
  15. float euroCoinValues [] = {2.00, 1.00, 0.50, 0.20, 0.10, 0.05, 0.02, 0.01}; // Array of each coin value to loop
  16.  
  17. int i = 0; // loop counter
  18.  
  19. int jarCount = 0;
  20.  
  21. float totalEurosInJar = 0;
  22.  
  23. for (i; i < 8; i++) {
  24.  
  25. if(euroCoinValues[i] >= 1){
  26.  
  27. printf("\n€ %.2f euro coins: " , euroCoinValues[i]);
  28.  
  29. }//if
  30.  
  31. else {
  32.  
  33. printf("\n€ %.2f euro cent coins: ", euroCoinValues[i]);
  34.  
  35. }//else
  36.  
  37. scanf("%d", &jarCount);
  38.  
  39. totalEurosInJar += jarCount * euroCoinValues[i];
  40.  
  41. }//for loop
  42.  
  43. printf("\nTotal Euros in the jar: € %.2f \n", totalEurosInJar);
  44.  
  45.  
  46. }//calculate Euros in a jar
Success #stdin #stdout 0s 5320KB
stdin
5
2
2
5
15
1
1
2
stdout
€ 2.00 euro coins: 
€ 1.00 euro coins: 
€ 0.50 euro cent coins: 
€ 0.20 euro cent coins: 
€ 0.10 euro cent coins: 
€ 0.05 euro cent coins: 
€ 0.02 euro cent coins: 
€ 0.01 euro cent coins: 
Total Euros in the jar: € 15.59