Advertisement
Spocoman

02. Report System

Sep 11th, 2023
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int neededSum, cashSum = 0, cardSum = 0, cashCount = 0, cardCount = 0, counter = 0;
  8.     cin >> neededSum;
  9.  
  10.     string command;
  11.     cin >> command;
  12.  
  13.     while (command != "End") {
  14.  
  15.         int sumTransaction = stoi(command);
  16.  
  17.         if (counter % 2 == 0 && sumTransaction > 0 && sumTransaction <= 100) {
  18.             neededSum -= sumTransaction;
  19.             cashSum += sumTransaction;
  20.             cout << "Product sold!\n";
  21.             cashCount++;
  22.         }
  23.         else if (counter % 2 == 1 && sumTransaction >= 10) {
  24.             neededSum -= sumTransaction;
  25.             cardSum += sumTransaction;
  26.             cout << "Product sold!\n";
  27.             cardCount++;
  28.         }
  29.         else {
  30.             cout << "Error in transaction!\n";
  31.         }
  32.  
  33.         if (neededSum <= 0) {
  34.             break;
  35.         }
  36.  
  37.         counter++;
  38.         cin >> command;
  39.     }
  40.  
  41.     if (command == "End") {
  42.         cout << "Failed to collect required money for charity.\n";
  43.     }
  44.     else {
  45.         printf("Average CS: %.2f\nAverage CC: %.2f\n", 1.0 * cashSum / cashCount, 1.0 * cardSum / cardCount);
  46.     }
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement