Advertisement
Spocoman

Easter Shop

Sep 18th, 2023
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int availableEggs, eggs, soldEggs = 0;
  7.     cin >> availableEggs;
  8.  
  9.     string input;
  10.     cin >> input;
  11.  
  12.     while (input != "Close") {
  13.         cin >> eggs;
  14.  
  15.         if (input == "Buy") {
  16.             if (availableEggs - eggs < 0) {
  17.                 break;
  18.             }
  19.             availableEggs -= eggs;
  20.             soldEggs += eggs;
  21.         }
  22.         else if (input == "Fill") {
  23.             availableEggs += eggs;
  24.         }
  25.  
  26.         cin >> input;
  27.     }
  28.  
  29.     if (input == "Close") {
  30.         cout << "Store is closed!\n"
  31.             << soldEggs << " eggs sold.\n";
  32.     }
  33.     else {
  34.         cout << "Not enough eggs in store!\n"
  35.             << "You can buy only " << availableEggs << ".\n";
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement