fork download
  1.  
  2. //Carl Argila CSC5 Chapter 2, P. 83, #11
  3. //
  4. /**************************************************************
  5.  *
  6.  * COMPUTE DISTANCE PER TANK OF GAS
  7.  * ____________________________________________________________
  8.  * This program computes the distance a car can travel on one
  9.  * tank of gas based on gas tank capacity and average
  10.  * miles-per-gallon (MPG) rating for city and highway driving.
  11.  *
  12.  * Computation is based on the formula:
  13.  * Distance = Number of Gallons x Average Miles per Gallon
  14.  * ____________________________________________________________
  15.  * INPUT
  16.  * tankCapacity : Gas tank capacity in gallons
  17.  * mpgCity : Average MPG for city driving
  18.  * mpgHighway : Average MPG for highway driving
  19.  *
  20.  * OUTPUT
  21.  * distance : Distance car can travel
  22.  *
  23.  **************************************************************/
  24. #include <iostream>
  25. #include <iomanip>
  26. using namespace std;
  27. int main ()
  28. {
  29. float tankCapacity; //INPUT - Gas tank capacity in gallons
  30. float mpgCity; //INPUT - Average MPG for city driving
  31. float mpgHighway; //INPUT - Average MPG for highway driving
  32. float distance; //OUTPUT - Distance car can travel
  33. //
  34. // Initialize Program Variables
  35. tankCapacity = 200.0;
  36. mpgCity = 99.5;
  37. mpgHighway = 99.8;
  38. //
  39. // Compute Distance Traveled City
  40. distance = tankCapacity * mpgCity;
  41. //
  42. // Output Result
  43. cout << "The car can travel " << distance << " miles in town." << endl;
  44. //
  45. // Compute Distance Traveled Highway
  46. distance = tankCapacity * mpgHighway;
  47. //
  48. // Output Result
  49. cout << "The car can travel " << distance << " miles highway." << endl;
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
The car can travel 19900 miles in town.
The car can travel 19960 miles highway.