fork download
  1. /******************************************************************
  2.  * Calculate Miles Per Gallon
  3.  *
  4.  * Determines a car's fuel efficiency, expressed as the number of
  5.  * miles it can travel on one gallon of gas.
  6.  ******************************************************************/
  7. #include <iostream>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. double gallons; // Number of gallons the tank holds
  14. double milesDriven; // Miles driven on a full tank
  15. double milesPerGallon; // Calculated fuel efficiency
  16.  
  17. // Get the tank capacity and the distance driven on a full tank.
  18. cout << "Enter the number of gallons the tank holds: ";
  19. cin >> gallons;
  20. cout << "Enter the number of miles driven on a full tank: ";
  21. cin >> milesDriven;
  22.  
  23. // Calculate the car's fuel efficiency.
  24. milesPerGallon = milesDriven / gallons;
  25.  
  26. // Display the result.
  27. cout << fixed << showpoint << setprecision(2);
  28. cout << "\nYour car gets " << milesPerGallon
  29. << " miles per gallon.\n";
  30.  
  31. return 0;
  32. }
  33.  
  34.  
Success #stdin #stdout 0s 5308KB
stdin
45 
150
stdout
Enter the number of gallons the tank holds: Enter the number of miles driven on a full tank: 
Your car gets 3.33 miles per gallon.