Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int weightA{500};
- const int weightB{1000};
- const int weightC{1500};
- const int weightD{2000};
- const int consumptionA{ 1 };
- const int consumptionB{ 4 };
- const int consumptionC{ 7 };
- const int consumptionD{ 9 };
- const int tankVolume{ 300 };
- int weight{ 0 };
- int distanceAB{ 0 };
- int distanceBC{ 0 };
- int volumeAB{ 0 };
- int volumeBC{ 0 };
- int neededVolume{ 0 };
- int consumption{ 0 };
- std::cout << "Enter cargo weight\n";
- std::cin >> weight;
- if (weight <= 0) { std::cout << "Incorrect weight! No cargo at all, no need to fly anywhere!\n"; return 0; }
- else if (weight < weightA) { consumption = consumptionA; }
- else if (weight < weightB) { consumption = consumptionB; }
- else if (weight < weightC) { consumption = consumptionC; }
- else if (weight < weightD) { consumption = consumptionD; }
- else { std::cout << "Cargo is too heavy, flight impossible!\n"; return 0; }
- std::cout << "Enter distance from A to B\n";
- std::cin >> distanceAB;
- std::cout << "Enter distance from B to C\n";
- std::cin >> distanceBC;
- volumeAB = distanceAB * consumption;
- volumeBC = distanceBC * consumption;
- if (volumeAB > tankVolume or volumeBC > tankVolume)
- {
- std::cout << "Distance from:\n" <<
- "A to B: " << (volumeAB > tankVolume ? "too long\n" : "good\n") <<
- "B to C: " << (volumeBC > tankVolume ? "too long\n" : "good\n") <<
- "Flight impossible!\n";
- return 0;
- }
- neededVolume = volumeBC - (tankVolume - volumeAB);
- if (neededVolume > 0)
- {
- std::cout << "Need additional " << neededVolume << " liters to tank!\n";
- }
- else
- {
- std::cout << "Do not need additional petrol!\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment