Untitled


SUBMITTED BY: holier

DATE: July 3, 2017, 7:57 p.m.

FORMAT: Text only

SIZE: 2.4 kB

HITS: 623

  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int main()
  5. {
  6. for (int execution = 1; execution <= 2; execution++)
  7. {
  8. double beginningRead, endingRead, reqGallons, avgMPG, price1, price2, price3, avgPPG, OneMileTrip;
  9. char answer = 'y';
  10. double totalMiles = 0, gallonsPurchased = 0;
  11. int count = 0;
  12. while (answer == 'y' || answer == 'Y')
  13. {
  14. first:
  15. cout << "Enter the beginning odomerter reading: ";
  16. cin >> beginningRead;
  17. if (count != 0 && beginningRead <= endingRead)
  18. {
  19. cout << "Your beginning odometer reading must be greater than the prior ending odometer reading.\n";
  20. goto first;
  21. }
  22. count++,
  23. cout << "Enter the ending odometer reading: ";
  24. cin >> endingRead;
  25. if (endingRead < beginningRead)
  26. {
  27. cout << "The ending odometer reading must be greater than the beginning odometer reading.\n";
  28. goto first;
  29. }
  30. second:
  31. cout << "Enter the gallons required for your full-up: ";
  32. cin >> reqGallons;
  33. if (reqGallons <= 0)
  34. {
  35. cout << "The required amount of gallons must be greater than 0.\n";
  36. goto second;
  37. }
  38. totalMiles += (endingRead - beginningRead);
  39. gallonsPurchased += reqGallons;
  40. cout << "Enter y to enter more readings or n to continue: ";
  41. cin >> answer;
  42. }
  43. cout << "\n";
  44. avgMPG = totalMiles/gallonsPurchased;
  45. for ( int station = 1; station <= 3; station++)
  46. {
  47. cout << "Enter the price per gallon at station #" << station << ": $";
  48. if (station == 1)
  49. {
  50. cin >> price1;
  51. }
  52. if (station == 2)
  53. {
  54. cin >> price2;
  55. }
  56. if (station == 3)
  57. {
  58. cin >> price3;
  59. }
  60. }
  61. avgPPG = (price1 + price2 + price3) / 3;
  62. OneMileTrip = avgPPG / avgMPG;
  63. cout << "\nYour car's average mile per gallon is: " << avgMPG << " mpg" << endl;
  64. cout << "You bought gas at an average $" << setprecision(2) << fixed << avgPPG << " per gallon\n";
  65. cout << "The cost for your car to go 1 mile is $" << setprecision(2) << fixed << OneMileTrip << endl;
  66. if (avgMPG > 0 && avgMPG <= 15)
  67. {
  68. cout << "Your car is very inefficient.\n\n\n";
  69. }
  70. if (avgMPG >= 16 && avgMPG <= 30)
  71. {
  72. cout << "Your car's efficiency is OK.\n\n\n";
  73. }
  74. if (avgMPG >= 31)
  75. {
  76. cout << "Your car is very efficient.\n\n\n";
  77. }
  78. }
  79. system ("pause");
  80. return 0;
  81. }

comments powered by Disqus