fork download
  1. // Eric Bernal Chapter 2, P. 83 #11 CS1A
  2. /******************************************************************************
  3. Compute distance per tank of gas
  4. *_______________________________________________________________________________
  5. This program will calculate the distance a car could travel based on it's tank
  6. capacity.
  7.  
  8. Computation formula:
  9. Distance = Tank Capacity x Average Mile per Gallon
  10. *_______________________________________________________________________________
  11. INPUT
  12. Tankcapacity : Amount of gas gallons the car can carry
  13. mpgCity : Average mpg in city
  14. mpgHighway: Average mpg at highway speeds
  15.  
  16. OUTPUT
  17. Distance : The distance the car could travel
  18. *******************************************************************************/
  19.  
  20. #include <iostream>
  21. using namespace std;
  22.  
  23. int main() {
  24.  
  25. float Tankcapacity; // INPUT = Amount of gas gallons the car can carry
  26. float mpgCity; // INPUT = Average mpg in city
  27. float mpgHighway; // INPUT = mpgHighway = Average mpg at highway speeds
  28. float Distance; // OUTPUT = Distance the car traveled
  29.  
  30.  
  31. Tankcapacity = 20;
  32. mpgCity = 21.5;
  33. mpgHighway = 26.8;
  34.  
  35. // Calculate distance in city
  36. Distance = Tankcapacity * mpgCity;
  37.  
  38. //Output results for city
  39. cout << "The car can travel " << Distance << " miles in the city." << endl;
  40.  
  41. // Calculate distance in highway
  42. Distance = Tankcapacity * mpgHighway;
  43.  
  44. //Output results for highway
  45. cout << "The car can travel " << Distance << " miles on the highway." << endl;
  46. return 0;
  47. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
The car can travel 430 miles in the city.
The car can travel 536 miles on the highway.