0

我问过我的同学,他们都不知道这是为什么。该计划应该是一个银行计划。我最初在我的功能中特别注意到了问题findCustomer。它应该做的是获取结构“帐户”的某个部分,查找帐号是否与您输入的输入匹配,然后将其声明为匹配。

int findCustomer(account arr[], int customers)
{
    int index;

    cout << "Account Number?: ";
    cin >> index;

    for (int i = 0; i <= customers + 1; i++)
        if (arr[i].acctNum == index)
        {
            cout << "You dun good!"; //I put this here to try to figure out what the problem was when it was passing in.
            return i;
            break;
        }
        else if (arr[i].acctNum != index)
        {
            cout << "Account Number (" << index << ") Does Not exist!" << endl;
            system("Pause");
            system("CLS");
            return -1;
        }

之后,它应该传递给存款/取款功能(它们的行为相同,但差异很小)。

void deposit(account arr[], int customers)
{
    char type;
    float money;
    int i;
    i = findCustomer(arr, customers);
    cout << i << "At this point" << endl;    
    if (i = -1)
    {
        cout << "You dun goofed!"; //again put here as a trigger
        // what normally goes here is a return; statement to break the function
    }


    type = submenu();

    cout << "How much would you like to deposit?: ";
    cin >> money;

    cout << "Number \t Name \t Balance" << endl;
    cout << "=========================================" << endl;
    if (type = 's')
    {    arr[i].sBal += money;
        cout << arr[i].acctNum << "\t" << arr[i].name << "\t" << arr[i].sBal;
    }
    else if (type = 'c')
    {    arr[i].cBal += money;
        cout << arr[i].acctNum << "\t" << arr[i].name << "\t" << arr[i].cBal;
    }
}

我得到的输出表明在函数中间有一个从 0 到 -1 的变化,而没有任何声明这样做(让我头上有一个巨大的 wth),这当然会破坏整个函数。我似乎在读取某些据说已在以前的函数中加载的帐号时也遇到了问题。任何和所有的帮助将不胜感激。

4

0 回答 0