Привет, моя программа почему-то не работает. Я использую функции с массивами.
#include <stdio.h> /* Variable declarations */ /* initial balance */ float promptInitialBalance(void); /*get intended number of deposits */ int promptIntendedNumDeposits(void); /*get intended number of withdrawals */ int promptIntendedNumWithdrawals(void); /*accept account deposits*/ float promptDeposits(float balance,int numDeposits, float depositRecords[5]); /* accept accont withdrawals */ float promptWithdrawals(float balance, int numWithdrawals, float withdrawalRecords[5]); /* display summary of closing account balance */ void printClosingBalanceSummary(float balance); // displays bank record */ void printBankRecord(float balance_0, float balance, int numDeposits, int numWithdrawals, float depositRecords[5], float withdrawalRecords[5]); /* start main */ int main(void) { float balance_0 = 0.0; /* starting balance */ float balance = 0.0; /* total balance */ int numDeposits=0; /* number of deposits */ int numWithdrawals=0; /* number of withdrawals */ float depositRecords[5]; /* record of valid deposit amounts */ float withdrawalRecords[5]; /* record of valid withdrawal amounts */ printf("Welcome to the Computer Banking System\n"); balance_0 = promptInitialBalance(); /* updated total balance with starting balance */ balance = balance_0; numDeposits = promptInitialBalance(); numWithdrawals = promptIntendedNumWithdrawals(); printf("\n"); balance = promptDeposits(balance, numDeposits, depositRecords); printf("\n"); balance = promptWithdrawals(balance, numWithdrawals, withdrawalRecords); printClosingBalanceSummary(balance); printBankRecord(balance_0, balance, numDeposits, numWithdrawals, depositRecords, withdrawalRecords); return 0; } /* Function Definitions*/ float promptInitialBalance(void) { float balance_0 = 0.0; /* starting balance */ /* continuously prompt user for a starting account balance*/ while (balance_0 < 0.0) { printf("\nEnter your current balance in dollars and cents: "); scanf("%lf", &balance_0); if (balance_0 >= 0.0) break; else printf("*** Beginning balance must be at least zero, please re-enter.\n"); } return balance_0; } int promptIntendedNumDeposits(void) { int numDeposits = 0; // number of deposits /* continuously prompt user for the number of intended deposits */ while (numDeposits < 0 || numDeposits > 5) { printf("\nEnter the number of deposits (0 - 5): "); scanf("%d", &numDeposits); if (numDeposits >= 0 && numDeposits <= 5) break; else printf("*** Invalid number of deposits, please re-enter.\n"); } return numDeposits; } int promptIntendedNumWithdrawals(void) { int numWithdrawals = 0; /*number of withdrawals*/ /*continuously prompt user for the number of intended withdrawals*/ while (numWithdrawals < 0 || numWithdrawals > 5) { printf("\nEnter the number of withdrawals (0 - 5): "); scanf("%d", &numWithdrawals); if (numWithdrawals >= 0 && numWithdrawals <= 5) break; else printf("*** Invalid number of withdrawals, please re-enter.\n"); } return numWithdrawals; } float promptDeposits(float balance, int numDeposits, float depositRecords[5]) { /* prompt the user to provide a deposit amount until we have enough valid amounds */ int depositCount = 0; float depositAmount = 0.0; while (depositCount < numDeposits) { printf("Enter the amount of deposit #%d: ", depositCount + 1); scanf("%lf", &depositAmount); if (depositAmount >= 0.0) { depositRecords[depositCount] = depositAmount; balance += depositAmount; depositCount++; } else printf("*** Deposit amount must be greater than or equal to zero, please try again.\n\n"); } return balance; } float promptWithdrawals(float balance, int numWithdrawals, float withdrawalRecords[5]) { /* prompt the user to provide a withdrawal amount until we have enough valid amounts */ int withdrawalCount = 0; float withdrawalAmount = 0.0; while (withdrawalCount < numWithdrawals) { printf("Enter the amount of withdrawal #%d: ", withdrawalCount + 1); scanf("%lf", &withdrawalAmount); if (withdrawalAmount >= 0.0) { if ((balance - withdrawalAmount) < 0.0) { printf("*** Withdrawal amount exceeds current balance.\n\n"); } else { withdrawalRecords[withdrawalCount] = withdrawalAmount; balance -= withdrawalAmount; withdrawalCount++; } } else printf("*** Withdrawal amount must be greater than or equal to zero, please try again.\n\n"); } return balance; } void printClosingBalanceSummary(float balance) { printf("\n*** The closing balance is: $%.2f ***\n", balance); if (balance >= 50000.00) { printf("*** It is time to invest some money! ***\n"); } else if (balance >= 15000.00 && balance <= 49999.9) { printf("*** Maybe you should consider a CD. ***\n"); } else if (balance >= 1000.00 && balance <= 14999.99) { printf("*** Keep up the good work! ***\n"); } else if (balance >= 0.0 && balance <= 999.99) { printf("*** Your balance is getting low! ***\n"); } } void printBankRecord(float balance_0, float balance, int numDeposits, int numWithdrawals, float depositRecords[5], float withdrawalRecords[5]) { printf("\n"); printf(" *** Bank Record ***\n\n"); printf("Starting Balance: $ %15.2f\n\n", balance_0); int i=0; for (i = 0; i < numDeposits; i++) { printf("Deposit #%d: %.2f\n", i + 1, depositRecords[i]); } for (i = 0; i < numWithdrawals; i++) { printf("Withdrawal #%d: %.2f\n", i + 1, withdrawalRecords[i]); } printf("\n"); printf("Ending Balance: $ %.2f\n\n", balance); }
Что я уже пробовал:
Он продолжает говорить, что я объявляется только один раз. Я не знаю, как это исправить.
спасибо.
Patrice T
Сообщите точное сообщение об ошибке и положение.
Richard MacCutchan
Что такое "это"? Пожалуйста, покажите полное сообщение об ошибке и объясните, к какой строке оно относится.