avr39ripe

cppPlaneTankCalculator

Mar 2nd, 2021 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     const int weightA{500};
  6.     const int weightB{1000};
  7.     const int weightC{1500};
  8.     const int weightD{2000};
  9.  
  10.     const int consumptionA{ 1 };
  11.     const int consumptionB{ 4 };
  12.     const int consumptionC{ 7 };
  13.     const int consumptionD{ 9 };
  14.  
  15.     const int tankVolume{ 300 };
  16.  
  17.     int weight{ 0 };
  18.     int distanceAB{ 0 };
  19.     int distanceBC{ 0 };
  20.     int volumeAB{ 0 };
  21.     int volumeBC{ 0 };
  22.     int neededVolume{ 0 };
  23.     int consumption{ 0 };
  24.  
  25.     std::cout << "Enter cargo weight\n";
  26.     std::cin >> weight;
  27.  
  28.     if (weight <= 0) { std::cout << "Incorrect weight! No cargo at all, no need to fly anywhere!\n"; return 0; }
  29.     else if (weight < weightA) { consumption = consumptionA; }
  30.     else if (weight < weightB) { consumption = consumptionB; }
  31.     else if (weight < weightC) { consumption = consumptionC; }
  32.     else if (weight < weightD) { consumption = consumptionD; }
  33.     else { std::cout << "Cargo is too heavy, flight impossible!\n"; return 0; }
  34.  
  35.     std::cout << "Enter distance from A to B\n";
  36.     std::cin >> distanceAB;
  37.     std::cout << "Enter distance from B to C\n";
  38.     std::cin >> distanceBC;
  39.  
  40.     volumeAB = distanceAB * consumption;
  41.     volumeBC = distanceBC * consumption;
  42.  
  43.  
  44.     if (volumeAB > tankVolume or volumeBC > tankVolume)
  45.     {
  46.         std::cout << "Distance from:\n" <<
  47.             "A to B: " << (volumeAB > tankVolume ? "too long\n" : "good\n") <<
  48.             "B to C: " << (volumeBC > tankVolume ? "too long\n" : "good\n") <<
  49.             "Flight impossible!\n";
  50.         return 0;
  51.     }
  52.    
  53.     neededVolume = volumeBC - (tankVolume - volumeAB);
  54.  
  55.     if (neededVolume > 0)
  56.     {
  57.         std::cout << "Need additional " << neededVolume << " liters to tank!\n";
  58.     }
  59.     else
  60.     {
  61.         std::cout << "Do not need additional petrol!\n";
  62.     }
  63.  
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment