This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2024_Stanislav_Mykhailenko/Lesson_2/Task_1/main.cpp

58 lines
1.4 KiB
C++
Raw Permalink Normal View History

2024-06-24 15:19:29 +00:00
#include <iostream>
using namespace std;
int main()
{
int accounts[10];
for (int account = 0; account < 10; ++account)
accounts[account] = 0;
while (true) {
int action = 0;
cout << "Enter action (1 - add money, 2 - remove money, 3 - display all balances): ";
cin >> action;
2024-07-20 11:58:27 +00:00
if (action < 1 || action > 3) {
cout << "Invalid action" << endl;
continue;
}
if (action != 3) {
2024-06-24 15:19:29 +00:00
int number = 0;
int money = 0;
cout << "Enter account number: ";
cin >> number;
2024-07-20 11:58:27 +00:00
if (number < 0 || number > 10) {
2024-06-24 15:19:29 +00:00
cout << "Invalid account number." << endl;
2024-07-20 11:58:27 +00:00
continue;
}
cout << "Enter the amount of money: ";
cin >> money;
if (money <= 0) {
cout << "The amount must be positive." << endl;
continue;
}
if (action == 1) {
accounts[number] += money;
cout << "Money added." << endl;
} else if (accounts[number] >= money) {
accounts[number] -= money;
cout << "Money removed." << endl;
} else
cout << "Not enough money." << endl;
} else
2024-06-24 15:19:29 +00:00
for (int account = 0; account < 10; ++account)
cout << "Account " << account << ": " << accounts[account] << endl;
}
return 0;
}