fork download
  1. //Diego Martinez CSC5 Chapter 3, P. 143,#1
  2.  
  3. /*******************************************************************************
  4. * Calculating miles per gallon
  5. * ______________________________________________________________________________
  6. * This program calculates a car’s gas mileage in miles per gallon (MPG).
  7. *
  8. * Computation is based on the Formula:
  9. * Miles per Gallon = Gallons of Gas Used /Miles Driven
  10. * _____________________________________________________________________________
  11. * INPUT
  12. * gallons
  13. * miles
  14. *
  15. * OUTPUT
  16. * miles per gallon
  17. *******************************************************************************/
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main() {
  22. double gallons, miles, mpg;
  23.  
  24. // Ask the user for the number of gallons the car can hold
  25. cout << "Enter the number of gallons the car can hold: ";
  26. cin >> gallons;
  27.  
  28. // Ask the user for the number of miles the car can travel on a full tank
  29. cout << "Enter the number of miles the car can be driven on a full tank: ";
  30. cin >> miles;
  31.  
  32. // Calculate miles per gallon
  33. mpg = miles / gallons;
  34.  
  35. // Display the result
  36. cout << "The car can travel " << mpg << " miles per gallon." << endl;
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter the number of gallons the car can hold: Enter the number of miles the car can be driven on a full tank: The car can travel 1.48681 miles per gallon.