fork download
  1. //Andrew Alspaugh CS1A Chapter 3, p. 143, #1
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Calculate Gas Mileage
  6.  *
  7.  * ___________________________________________________________________________
  8.  * This program calculates the distance a car goes on one gallon of gas
  9.  * ___________________________________________________________________________
  10.  * INPUT
  11.  * GasCapacity :Gallons the tank holds
  12.  * Distance :Distance car can travel on full tank
  13.  *
  14.  * OUTPUT
  15.  * MPG :Distance car can travel per gallon
  16.  * __________________________________________________________________________
  17.  * ***************************************************************************/
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23. double GasCapacity; //INPUT - Gallons the tank holds
  24. double Distance; //INPUT - Distance car travels on full tank
  25. double MPG; //OUTPUT - Distance per gallom
  26.  
  27. MPG = Distance / GasCapacity;
  28.  
  29. cout<<"Enter gallons of gas tank holds"<<endl;
  30. cin>>GasCapacity;
  31.  
  32. cout<<"Enter Distance in Miles"<<endl;
  33. cin>>Distance;
  34.  
  35. cout<<"Miles per Gallon is " << MPG;
  36. return 0;
  37. }
Success #stdin #stdout 0s 5316KB
stdin
15
235
stdout
Enter gallons of gas tank holds
Enter Distance in Miles
Miles per Gallon is 1.48502