fork download
  1. //Chloe Yau CIC5 Chapter 3, P. 143, #1
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTING MILES PER GALLON
  6.  * _____________________________________________________________________________
  7.  * This program calculates a car's gas mileage and display the values on the
  8.  * screen by entering the number of gallons of gas the car can hold and the
  9.  * number of miles it can be driven on a full tank.
  10.  * _____________________________________________________________________________
  11.  * INPUT
  12.  * gallons : Gas tank capacity in gallons
  13.  * miles : The number of miles the car can drive on a full tank
  14.  * OUTPUT
  15.  * milesPerGallon : Miles that can be driven per gallon of gas
  16.  *
  17.  ******************************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. float gallons; // INPUT - Gas tank capacity in gallons
  25. float miles; // INPUT - Number of miles the car can drive on a full tank
  26. float mpg; // OUTPUT - Miles that can be driven per gallon of gas
  27. //
  28. // Ask for User Inputs for Gallons and Miles
  29. cout << "How many gallons the car can store: ";
  30. cin >> gallons;
  31. cout << gallons;
  32.  
  33. cout << "\nHow many miles the car can drive with a full tank: ";
  34. cin >> miles;
  35. cout << miles;
  36. //
  37. // Computing Miles Per Gallon
  38. mpg = miles / gallons;
  39. //
  40. // Display Output Result
  41. cout << "\nThe car can drive for " << mpg;
  42. cout << " miles per gallon.";
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
How many gallons the car can store: 1.00199e-22
How many miles the car can drive with a full tank: 4.59149e-41
The car can drive for 4.58238e-19 miles per gallon.