fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 3 P.143 #1
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Miles Per Gallon
  6.  * ___________________________________________________________________________
  7.  * This program computes a car's gas mileage based on the number of gallons
  8.  * and the number of miles driven on a full tank.
  9.  *
  10.  * The formula that will be used:
  11.  * miles per gallon = miles / gallon
  12.  * ___________________________________________________________________________
  13.  * INPUT
  14.  * gallons // Amount of gallons the car can hold
  15.  * miles // Amount of miles the car can drive on full tank
  16.  * OUTPUT
  17.  * milesPerGallon // Amount of miles driven per gallon
  18.  ****************************************************************************/
  19. #include <iostream>
  20. #include <iomanip>
  21. using namespace std;
  22. int main()
  23. {
  24. float gallons; //INPUT - amount of gallons the car can hold
  25. float miles; //INPUT - amount of miles the car can drive on full tank
  26. float milesPerGallon; //OUTPUT - amount of miles driven per gallon
  27. //
  28. //User input
  29. cin >> gallons;
  30. cin >> miles;
  31. //
  32. //Calculate Miles Per Gallon
  33. milesPerGallon = miles / gallons;
  34. //
  35. //Display
  36. cout << "The car gets " << milesPerGallon << " miles per gallon.";
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5316KB
stdin
14.5
395.8
stdout
The car gets 27.2966 miles per gallon.