fork download
  1. #include <stdio.h>
  2.  
  3. double calculateCharges(double hours);
  4. int main(void)
  5. {
  6. printf("Car \tHours \tCharges\n");
  7. double car1 = calculateCharges(1.5);
  8. double car2 = calculateCharges(4.0);
  9. double car3 = calculateCharges(24.0);
  10. double total = car1 + car2 + car3;
  11.  
  12. printf("1 \t\t1.5 \t%.2f\n", car1);
  13. printf("2 \t\t4.0 \t%.2f\n", car2);
  14. printf("3 \t\t24.0 \t%.2f\n", car3);
  15. printf("TOTAL \t29.5\t%.2f\n", total);
  16. }
  17. double calculateCharges(double hours)
  18. {
  19. double charges;
  20. if (hours <= 3)
  21. {
  22. charges = 2.00;
  23. }
  24. else if(hours == 24)
  25. {
  26. charges = 10.00;
  27. }
  28. else
  29. {
  30. charges = 2.00 + (hours - 3) * 0.50;
  31. }
  32. return charges;
  33. }
  34.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Car 	Hours 	Charges
1 		1.5 	2.00
2 		4.0 	2.50
3 		24.0 	10.00
TOTAL 	29.5	14.50