嗨我的程序由于某种原因没有运行。我正在使用带数组的函数。 [英] Hi my program is not running for some reason. I'm using functions with arrays.

查看:78
本文介绍了嗨我的程序由于某种原因没有运行。我正在使用带数组的函数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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);
    
}





我的尝试:



它一直说我只宣布一次。我不知道如何解决这个问题。



谢谢。



What I have tried:

It keeps saying that i is only declared once. I'm not sure how to fix this.

thanks.

推荐答案

%。2f ** * \ n,余额);

如果(余额> = 50000 00
{
printf( < span class =code-string> ***是时候投入一些钱了!*** \ n);
}
else if (余额> = 15000 00 && balance< = 49999 9
{
printf( ***也许你应该考虑一张CD。*** \ n );
}
else if (余额> = 1000 00 &&余额< = 14999 99
{
printf( ***保持良好的工作!*** \ n);
}
其他 如果(余额> = 0 0 && balance< = 999 。< span class =code-digit> 99 )
{
printf( ***你的余额越来越低!*** \ n);
}
}

void printBankRecord( float balance_0, float balance, int numDeposits, int numWithdrawals, float depositRecords [ 5 ], float withdrawRecords [ 5 ])
{

printf( \ n);

printf( ***银行记录*** \ n\ n );
printf( 起始余额:
%.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( 存款#%d:%。2f \ n,i + 1 ,depositRecords [i]);
}

for (i = 0 ; i< numWithdrawals; i ++)
{
printf( 提款#%d:%。2f \ n,i + 1 ,withdrawRecords [i]);
}

printf( \ n);

printf( 期末余额:
%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,平衡);

}
%.2f\n\n", balance); }





我的尝试:



它一直说我只宣布一次。我不知道如何解决这个问题。



谢谢。



What I have tried:

It keeps saying that i is only declared once. I'm not sure how to fix this.

thanks.


这篇关于嗨我的程序由于某种原因没有运行。我正在使用带数组的函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆