Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int neededSum, cashSum = 0, cardSum = 0, cashCount = 0, cardCount = 0, counter = 0;
- cin >> neededSum;
- string command;
- cin >> command;
- while (command != "End") {
- int sumTransaction = stoi(command);
- if (counter % 2 == 0 && sumTransaction > 0 && sumTransaction <= 100) {
- neededSum -= sumTransaction;
- cashSum += sumTransaction;
- cout << "Product sold!\n";
- cashCount++;
- }
- else if (counter % 2 == 1 && sumTransaction >= 10) {
- neededSum -= sumTransaction;
- cardSum += sumTransaction;
- cout << "Product sold!\n";
- cardCount++;
- }
- else {
- cout << "Error in transaction!\n";
- }
- if (neededSum <= 0) {
- break;
- }
- counter++;
- cin >> command;
- }
- if (command == "End") {
- cout << "Failed to collect required money for charity.\n";
- }
- else {
- printf("Average CS: %.2f\nAverage CC: %.2f\n", 1.0 * cashSum / cashCount, 1.0 * cardSum / cardCount);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement