fork download
  1. //Castulo Jason Quintero CSC5 Chapter 2, P. 83, #10
  2. //
  3. /**************************************************************
  4.  *
  5.  * COMPUTE MPG ON FULL TANK OF GAS
  6.  * ____________________________________________________________
  7.  * This program computes the MPG a car can travel on one
  8.  * tank of gas based on gas tank capacity and range of
  9.  * miles that can be driven before refueling.
  10.  *
  11.  * Computation is based on the formula:
  12.  * MPG = Range of Miles that can be driven / Number of Gallons
  13.  * ____________________________________________________________
  14.  * INPUT
  15.  * tankCapacity : Gas tank capacity in gallons
  16.  * mileRange: Range of Miles that can be driven
  17.  *
  18.  * OUTPUT
  19.  * MPG : MPG car can travel
  20.  *
  21.  **************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25. int main ()
  26. {
  27. float tankCapacity; //INPUT - Gas tank capacity in gallons
  28. float mileRange; //INPUT - Range of Miles that can be driven
  29. float MPG; //OUTPUT - MPG car gets
  30. //
  31. // Initialize Program Variables
  32. tankCapacity = 12.0;
  33. mileRange= 350.0;
  34. //
  35. // Compute MPG Traveled Highway
  36. MPG = mileRange / tankCapacity;
  37. //
  38. // Output Result
  39. cout << "The car gets " << MPG << " miles per gallon." << endl;
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
The car gets 29.1667  miles per gallon.