fork download
  1. //Ivy Whitney CSC 5 chp. 3, Q# 1
  2.  
  3. /************************************************************
  4. *
  5. *
  6. *CALCULATE A CAR'S GAS MILEAGE
  7. _____________________________________________________________
  8. *
  9. *
  10. * This program display the number of miles that may be driven
  11. * based on the amount of gas the user can hold in their car and
  12. * the number of miles that can be driven on a full tank.
  13. *
  14. * ==================Variables===============================
  15. *
  16. * INPUTs
  17. *
  18. * gasCapacity = Max amount of Gas the users car can hold
  19. * maxMiles = The number of miles that can be driven on a full tank
  20. *
  21. * OUTPUTs
  22. *
  23. * milesperGallon = The miles per gallon
  24. * ==========================================================
  25. * The MATH...
  26. *
  27. * milesperGallon = maxMiles / gasCapacity
  28. **************************************************************/
  29.  
  30. #include <iostream>
  31. #include <iomanip>
  32. #include <cmath>
  33.  
  34. using namespace std;
  35. int main() {
  36.  
  37. //variable time!
  38.  
  39. double gasCapacity;
  40. double maxMiles;
  41. double milesperGallon;
  42.  
  43. //User inputs
  44.  
  45. cout << "ENTER YOUR MAX FUEL CAPACITY BELOW.\n";
  46. cin >> gasCapacity ;
  47. cout << "ENTER THE AMOUNT OF MILES YOU CAN DRIVE WITH";
  48. cout << "A FULL TANK OF GAS BELOW.\n";
  49. cin >> maxMiles ;
  50.  
  51.  
  52. milesperGallon = gasCapacity / maxMiles;
  53.  
  54.  
  55. cout << "YOUR MPG IS " << fixed << setprecision(2) << milesperGallon << ".";
  56. return 0;
  57.  
  58. }
Success #stdin #stdout 0.01s 5288KB
stdin
200
20
stdout
ENTER YOUR MAX FUEL CAPACITY BELOW.
ENTER THE AMOUNT OF MILES YOU CAN DRIVE WITHA FULL TANK OF GAS BELOW.
YOUR MPG IS 10.00.