fork download
  1. // C code
  2. // This progrm will calculate the total cost of a trip and the average daily trip cost and then display the output to the screen.
  3. // Code History: OBA - 06/18/16 - Created
  4. // OBA - 06/25/16 - Modified
  5. #include <stdio.h>
  6.  
  7. int main ()
  8. {
  9. /* variable definition: */
  10. float costGas, costFood, costLodg, totalCost, avgDail, numDay;
  11. int;
  12. /* Prompt the user for the cost of gas */
  13. printf("Please enter the amount of gas to purchase:40 \n");
  14. // Input costGas
  15. scanf("%f", &costGas);
  16. /* Promt the user for the cost of food */
  17. printf("Please enter the cost of food to purchase:30 \n");
  18. // Input costFood
  19. scanf("%f", &costFood);
  20. /* Promt the user for the cost of lodging */
  21. printf("Please enter the cost of lodging:100 \n");
  22. // Input costLodg
  23. scanf("%f", &costLodg);
  24. /* Promt the user for the number of days of the trip */
  25. printf("Please enter the number of days of the trip:2 \n");
  26. // Input numDay
  27. scanf("%f", &numDay);
  28.  
  29. scanf("%f", &totalCost);
  30.  
  31. // Calculate the total cost of the trip
  32. totalCost = costGas + costFood + costLodg;
  33. // Calculate the average daily trip cost (totalCost divided by number of days)
  34. avgDail= totalCost / 2;
  35.  
  36. // Print the result
  37. printf("The total cost of the trip is : %f\n", totalCost);
  38. printf("The average daily cost of the trip is : %f\n", avgDail);
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 2164KB
stdin
Standard input is empty
stdout
Please enter the amount of gas to purchase:40 
Please enter the cost of food to purchase:30 
Please enter the cost of lodging:100 
Please enter the number of days of the trip:2 
The total cost of the trip is : -1.090638
The average daily cost of the trip is : -0.545319