银行程序,提款功能不起作用? (C)

Banking Program, withdraw function doesn't work? (C)

出于某种原因,我无法在我的银行程序中使用提款功能...我认为我做的是正确的,因为这些功能与存款功能非常相似。

问题是如果程序没有正确构建,我似乎无法获得提款金额。提款功能应该与存款功能非常相似,对吗?因为您不是在帐户中存入价值,而是简单地从给定帐户中提取金额。如果账户没有足够的钱,那么它 returns 作为一个错误。这是我的代码:

#include <stdio.h>
#include <stdlib.h>

#define MAXNUMCUSTOMERS 10  // Maximum number of customers
#define MAXCUSTOMERNAME 20  // Max length of customer's name including null character at the end

// Function Prototypes
int DisplayMenu();
int userLogin(int acctNumber[MAXNUMCUSTOMERS]);
float acctBalance (int custIndex, float money[MAXNUMCUSTOMERS]);
float depositMoney (int custIndex, float money[MAXNUMCUSTOMERS]);
float withdrawFunds (int custIndex, float money[MAXNUMCUSTOMERS]);
/*
 * 
 */
int main(int argc, char** argv) {
    int acctNumber[MAXNUMCUSTOMERS] =
    {1111,2222,3333,4444,5555,6666,7777,8888,9999,10000};
    char customerName[MAXNUMCUSTOMERS][MAXCUSTOMERNAME] =
    {"Joe","Mary","bob","tim","sid","will","ray","les","quinn","helen"};
    float money[MAXNUMCUSTOMERS] = 
    {12.50,25.30,69.3,46.0,777.00,10000.,55.6,33.78,99.54,47895.33};
    int option = 0;
    int myAcct = -1;
    float myBalance = 0.0;

    // loop until done
    while (option != 6) {
        // Display menu - return option
        option = DisplayMenu();

        if (option == 0) { // customer login
            myAcct = userLogin(acctNumber);
            if (myAcct == -1)             {
                printf("Invalid account\n");
            } else {
                printf ("Welcome %s \n", customerName[myAcct]);
            }
        } else if (option == 1) { // deposit money
            myBalance = depositMoney (myAcct, money);
            if (myBalance < 0.0)
                printf("Account not found\n");
            else
                printf ("Your new account balance is: %.2f\n", myBalance);
        } else if (option == 2) { // withdraw money
            if (myBalance > 0.0)
                printf("Account not found\n");
            else
                printf ("Your new account balance is: %.2f\n", myBalance);
        } else if (option == 3) { // account balance
            myBalance = acctBalance (myAcct, money);
            if (myBalance < 0.0)
                printf("Account not found\n");
            else
                printf ("Your account balance is: %.2f\n", myBalance);
        } else if (option == 4) { // add a customer
        } else if (option == 5) { // delete a customer
        } else if (option == 6) { // exit
        }
        // exit program

    }   //end loop until done
    return (EXIT_SUCCESS);
}

int DisplayMenu() {
    int customerChoice;

    printf("Welcome to My Bank\n");
    printf("Enter an option from the menu\n");
    printf("\t 0 Customer Login\n");
    printf("\t 1 Deposit Money Login\n");
    printf("\t 2 Withdraw Money\n");
    printf("\t 3 Account Balance\n");
    printf("\t 4 Add a customer\n");
    printf("\t 5 delete a customer\n");
    printf("\t 6 Exit\n");

    scanf("%d", &customerChoice);
    return (customerChoice);
}

int userLogin(int acctNumber[MAXNUMCUSTOMERS])
{
    int customerIndex = -1;
    int accountNum;
    int i;

    // get the account number
    printf("Please enter your account number>");
    scanf("%d", &accountNum);

    // loop to find which index has customer information
    for (i=0; i < MAXNUMCUSTOMERS; i++)
    {
        if (accountNum == acctNumber[i])
            customerIndex = i;
    } // end loop
    return customerIndex;
 }
float acctBalance (int custIndex, float money[MAXNUMCUSTOMERS])
{
    float balance = -1.0;
    if (custIndex >= 0)
        balance = money[custIndex];
    return balance;
}
float depositMoney (int custIndex, float money[MAXNUMCUSTOMERS])
{
    float balance = -1.0;
    float deposit;
    if (custIndex >= 0)
    {
        // get the deposit amount
        printf ("Enter Deposit Amount>");
        scanf ("%f", &deposit);
        money[custIndex] = money[custIndex] + deposit;
        balance = money[custIndex];
    }
    return balance;
}
//my problem is down here. This section doesn't work???
float withdrawFunds (int custIndex, float money[MAXNUMCUSTOMERS]; 
{
    float balance = -1.0;
    float withdraw;
    if (custIndex >= 0)
    {
        //get withdraw amount
        printf ("Enter Withdraw Amount>");
        scanf ("%f", %withdraw);
        money[custIndex] = withdraw - money[custIndex];
        balance = money[custIndex];
    }
    return balance;
}

试试这个。 (这里没有实现检查账户是否有足够的钱)

float withdrawFunds (int custIndex, float money[MAXNUMCUSTOMERS]) // ; -> )
{
    float balance = -1.0;
    float withdraw;
    if (custIndex >= 0)
    {
        //get withdraw amount
        printf ("Enter Withdraw Amount>");
        scanf ("%f", &withdraw); // % -> &
        money[custIndex] = money[custIndex] - withdraw ; // correct the formula
        balance = money[custIndex];
    }
    return balance;
}