fork download
  1. //Zachary Abdollahi CS1A Chapter 3, P. 143, #1
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * MILES PER GALON
  6.  * _____________________________________________________________________________
  7.  *
  8.  * This program calculates a car's gas mileage based on the number of gallons of
  9.  * gas the car can hold and the number of miles it can be driven on a full tank.
  10.  *
  11.  * Computation is based on the formula:
  12.  * Miles per Gallon = Miles Driven / Gallons of Gas
  13.  * _____________________________________________________________________________
  14.  *
  15.  * INPUT
  16.  * gallons : Number of gallons of gas the car should hold
  17.  * miles : Number of miles driven on a full tank
  18.  *
  19.  * OUTPUT
  20.  * milesPerGallon : Number of miles the car gets per gallon
  21.  *
  22.  ******************************************************************************/
  23. #include <iostream>
  24. #include <iomanip>
  25. using namespace std;
  26. int main ()
  27. {
  28. float gallons; //INPUT - Number of gallons of gas the car can hold
  29. float miles; //INPUT - Number of miles driven on a full tank
  30. float milesPerGallon; //OUTPUT - Miles per gallon
  31.  
  32. //
  33. // Get Input from User
  34. cout << "Enter the number of gallons of gas the car can hold: ";
  35. cin >> gallons;
  36.  
  37. cout << "Enter the number of miles the car can be driven on a full tank: ";
  38. cin >> miles;
  39.  
  40. //
  41. // Compute Miles Per Gallon
  42. milesPerGallon = miles / gallons;
  43.  
  44. //
  45. // Output Result
  46. cout << "The car gets " << milesPerGallon << " miles per gallon." << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 5316KB
stdin
20
450
stdout
Enter the number of gallons of gas the car can hold: Enter the number of miles the car can be driven on a full tank: The car gets 22.5 miles per gallon.