fork download
  1. //Castulo Jason Quintero CSC5 Chapter 3, P. 143, #1
  2. //
  3. /**************************************************************
  4.  *
  5.  * Compute Miles per Gallon
  6.  * ____________________________________________________________
  7.  * This program calculate the miles per gallon.
  8.  *
  9.  * Computation is based on the formula:
  10.  * MPG = mileRange / tankCapacity
  11.  * ____________________________________________________________
  12.  * INPUT
  13.  * tankCapacity: Gas tank capacity in gallons
  14.  * mileRange: Range of Miles that can be driven
  15.  *
  16.  * OUTPUT
  17.  * MPG: miles per gallon
  18.  *
  19.  **************************************************************/
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main() {
  24. float tankCapacity; //INPUT - Gas tank capacity in gallons
  25. float mileRange; //INPUT - Range of Miles that can be driven
  26. float MPG; //OUTPUT - MPG car gets
  27. //
  28. cout << "Enter the number of gallons of gas the car can hold." << endl;
  29. cin >> tankCapacity;
  30. cout << "What is the number of miles it can be driven on a full tank?" << endl;
  31. cin >> mileRange;
  32. // Compute MPG
  33. MPG = mileRange / tankCapacity;
  34. //
  35. cout << MPG << " miles per gallon." << endl;
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5272KB
stdin
23 450
stdout
Enter the number of gallons of gas the car can hold.
What is the number of miles it can be driven on a full tank?
19.5652  miles per gallon.