Advertisement
DidiMilikina

04. Cake

Oct 31st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     int height_of_cake, width_of_cake;
  10.     cin >> width_of_cake >> height_of_cake;
  11.     int number_of_pieces = width_of_cake * height_of_cake;
  12.     string current_input;
  13.     cin >> current_input;
  14.     bool cake_is_over = false;
  15.  
  16.     while (current_input != "STOP")
  17.     {
  18.         int current_pieces_to_take = stoi(current_input);
  19.         if (current_pieces_to_take > number_of_pieces)
  20.         {
  21.             cake_is_over = true;
  22.             int needed_pieces = current_pieces_to_take - number_of_pieces;
  23.             cout << "No more cake left! You need "
  24.                 << needed_pieces
  25.                 << " pieces more."
  26.                 << endl;
  27.             break;
  28.         }
  29.         else
  30.         {
  31.             number_of_pieces -= current_pieces_to_take;
  32.         }
  33.         cin >> current_input;
  34.     }
  35.  
  36.     if (!cake_is_over)
  37.     {
  38.         cout << number_of_pieces << " pieces are left." << endl;
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement