fork download
  1. // Taylor Johnson CS1A Chapter 2, P. 82, #10
  2. //
  3. /******************************************************************************
  4.  * Compute Miles Per Gallon based on miles driven on one full tank
  5.  * ____________________________________________________________________________
  6.  * This Program will compute the average distance driven per gallon for a car
  7.  * based on its tank size and total miles driven on one full tank
  8.  *
  9.  * Will compute by the formula:
  10.  * MilesPergallon : Miles driven on one tank / Gallons per one full tank
  11.  * ____________________________________________________________________________
  12.  * INPUT
  13.  * Distance : Distance car can drive on one full tank
  14.  * TankSize : Amount of Gas the tank holds in Gallons
  15.  *
  16.  * OUTPUT
  17.  * MPG : Distance Car travels using one gallon of gas
  18.  * ***************************************************************************/
  19.  
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25. //Establich and Define Variables
  26. float MPG, Distance = 350.00, TankSize = 12;
  27. //
  28. //Divide number of miles driven by the tank size in gallons. Set value to MPG.
  29. MPG = Distance/TankSize;
  30. //Display result
  31. cout << "The car travels " << MPG << " miles per gallon!" << endl;
  32. // your code goes here
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
The car travels 29.1667 miles per gallon!