fork download
  1. //Amari Mosley CSC5 Chapter 3, P. 143, #1
  2. //https://i...content-available-to-author-only...e.com/myrecent
  3. /**************************************************************
  4.  *
  5.  * Miles Per Gallon
  6.  * ____________________________________________________________
  7.  * This program calculates a car's gas mileage.
  8.  
  9.  * Computation is based on the following formulas:
  10.  * MilePerGal = MaxMile / MaxGal
  11.  * ____________________________________________________________
  12.  * INPUT
  13.  * MaxGal : Number of gallons of gas the car can hold
  14. MaxMile : Number of miles the car can drive on a full tank of gas
  15.  
  16.  
  17.  * OUTPUT
  18. MilePerGal : Number of miles the car can drive per gallon
  19.  *
  20.  *
  21.  **************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. // Defining Main Function
  27. int main()
  28.  
  29. {
  30. // Define variables to hold gallons, miles, and miles per gallon
  31. double MaxGal, MaxMile, MilePerGal;
  32.  
  33. // Ask the user to enter the number of gallons of gas the car can hold
  34. cout << "Enter the number of gallons of gas the car can hold: ";
  35. cin >> MaxGal;
  36.  
  37. // Ask the user to enter the number of miles it can be driven on a full tank
  38. cout << "Enter the number of miles it can be driven on a full tank: ";
  39. cin >> MaxMile;
  40.  
  41. // Calculate the miles per gallon
  42. MilePerGal = MaxMile / MaxGal;
  43.  
  44. // Display the number of miles that may be driven per gallon of gas
  45. cout << "The car's gas mileage is " << MilePerGal << " miles per gallon." << endl;
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Enter the number of gallons of gas the car can hold: Enter the number of miles it can be driven on a full tank: The car's gas mileage is 1.48534 miles per gallon.