Advertisement
Spocoman

05. Travelling

Sep 11th, 2023
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string destination;
  7.     double budget, moneyOnHand, currentSum;
  8.  
  9.     while (true) {
  10.         cin >> destination;
  11.         if (destination == "End") {
  12.             break;
  13.         }
  14.         cin >> budget >> moneyOnHand;
  15.  
  16.         while (budget > moneyOnHand) {
  17.             cin >> currentSum;
  18.             moneyOnHand += currentSum;
  19.         }
  20.  
  21.         cout << "Going to " << destination << "!\n";
  22.     }
  23.  
  24.     return 0;
  25. }
  26.  
  27. Или леко тарикатската:)
  28.  
  29. #include <iostream>
  30.  
  31. using namespace std;
  32.  
  33. int main() {
  34.     string destination;
  35.     cin >> destination;
  36.  
  37.     double budget, currentSum;
  38.  
  39.     while (destination != "End") {
  40.         cin >> budget;
  41.  
  42.         while (budget > 0) {
  43.             cin >> currentSum;
  44.             budget -= currentSum;
  45.         }
  46.  
  47.         cout << "Going to " << destination << "!\n";
  48.         cin >> destination;
  49.     }
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement