fork download
  1. //Adam Sanchez CIS5 Chapter 2, P. 82, #10
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE NUMBER OF MILES PER GALLON
  6.  * _____________________________________________________________________________
  7.  * This program computes a cars number of miles per gallon with a given
  8.  * amount of gas and miles.
  9.  *
  10.  * Computation is based on the formula:
  11.  * MPG = Miles Driven / Gallons of Gas Used
  12.  * _____________________________________________________________________________
  13.  * Input
  14.  *
  15.  * Output
  16.  *
  17.  ******************************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. using namespace std;
  21. int main()
  22. {
  23. float miles; //INPUT - amount of miles driven
  24. float gallonofgas; //INPUT - amount of gallons of gas used
  25. float mpg; //OUTPUT - amount of mile travlled for every gallon of gas used
  26. //
  27. // Initialize Program Variables
  28. miles = 350;
  29. gallonofgas = 12;
  30. //
  31. // Compute Amount Of Miles Per Gallon Of Gas
  32. mpg = miles / gallonofgas;
  33. //
  34. // Output Results
  35. cout << "The car gets " << setprecision(2) << mpg;
  36. cout << " miles per gallon of gas." << endl;
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
The car gets 29 miles per gallon of gas.