Advertisement
Spocoman

Trip Expenses

Oct 5th, 2023
1,032
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 1
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int days;
  8.     cin >> days;
  9.     cin.ignore();
  10.  
  11.     string command;
  12.  
  13.     double dayCash = 0;
  14.  
  15.     for (int i = 0; i < days; i++) {
  16.         int dayProducts = 0;
  17.         dayCash += 60;
  18.  
  19.         while (true) {
  20.             getline(cin, command);
  21.             if (command == "Day over") {
  22.                 printf("Money left from today: %.2f.", dayCash);
  23.                 break;
  24.             }
  25.  
  26.             int productPrice = stoi(command);
  27.             if (productPrice <= dayCash) {
  28.                 dayCash -= productPrice;
  29.                 dayProducts++;
  30.             }
  31.  
  32.             if (dayCash == 0) {
  33.                 cout << "Daily limit exceeded!";
  34.                 break;
  35.             }
  36.         }
  37.         cout << " You've bought " << dayProducts << " products.\n";
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement