Как мы пишем программу на C ++ для управления банковским счетом с помощью классов? - PullRequest
0 голосов
/ 24 марта 2019

Мне нужно написать следующую программу для управления банковским счетом (в качестве домашней работы):

  1. Создайте прототип программы, используя именованный класс Account. Каждый класс характеризуется именем владельца и балансом.

  2. В программу должны быть добавлены следующие банковские операции: Владелец может снять сумму со своего счета. Добавить информацию об учетной записи. владелец может внести сумму на свой счет. Владелец может перевести сумму на другой счет. Владелец может проверить остаток на счете.

  3. Для проверки программы необходимо выполнить следующую программу: создать две учетные записи объекта А1 и А2; Депозит 500 в А1. Депозит 200 в A2. Снимите 100 с А1. Показать баланс для A1. Снять 50 с А2. Показать баланс для A2. Перевод 150 с А1 на А2.

Вот что я сделал. Я еще не добавил муравьиные классы, он еще не завершен.

#include <iostream>
using namespace std;
int main () {
    int password = 30718042;
    int OperationNumber, amount, CurrentBalance, AccountNumber, selection;
    cout <<"Welcome FATIH HANCER, please enter your password: ";
    cin >> password;

    while (password != 30718042) {
        cout <<"Please enter your password again. ";
        cin >> password;
    }

    while (password == 30718042) {
        cout <<"Please enter your operation number: "<<endl<<"1. Withdraw"<<endl<<"2. Deposit"<<endl<<"3. Transfer"<<endl<<"4. Check the balance"<<endl;
        cin >> OperationNumber;
        if (OperationNumber == 1) {
            cout <<"Please enter the amount you would like to withdraw. "<<endl;
            cin >> amount;
            int CurrentBalance -= amount;
            cout <<"Deposit action is completed. Your new balance is "<<CurrentBalance<<endl;
        }
        cout <<"\nIf there is another operation to do, please press 1. Otherwise, you will be redirected to the main menu. "<<endl;
        cin >> selection;
        if (selection != 1) {
            cout <<"Thank you for preferring us. "<<endl;
            break;
        } 
    }
    if (OperationNumber == 2) {
        cout <<"Please enter the amount you would like to deposit."<<endl;
        cin >> amount;
        int CurrentBalance += amount;
        cout <<"Deposit action is completed. Your new balance is "<<CurrentBalance<<endl;
    }
    if (OperationNumber == 3) {
        cout <<"Please enter the account number of whom you would like to transfer."<<endl;
        cin >> AccountNumber;
        while (AccountNumber == 30718059) {
            cout <<"Please enter the amount of money you would like to transfer to ABDULRAHMAN SUBH's account"<<endl;
            cin >> amount;
            int CurrentBalance -= amount;
            cout <<"Deposit action is completed. Your new balance is "<<CurrentBalance<<endl;
            break;
        };
    }

    while (AccountNumber != 30718059) {
        cout <<"The user couldn't be found. ";
        break;
    }

    if (OperationNumber == 4) {
        cout <<"Your balance is "<<CurrentBalance<<endl;
    }
    return 0;
}

Как я могу исправить [Error] expected initializer before '-=' token? Кроме того, я хочу, чтобы баланс можно было менять, снимая, внося и переводя деньги.

1 Ответ

0 голосов
/ 24 марта 2019
int CurrentBalance -= amount;

Вам необходимо объявить и инициализировать переменную CurrentBalance, например,

int CurrentBalance = 100;
CurrentBalance -= amount;

- = - эта операция означает CurrentBalance = CurrentBalance - amount;

...