Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        3年前关闭。
                                                                                            
                
        
因此,我正在编写一个程序来计算银行对帐单(学校实验室),我正在执行的此功能是计算已从帐户中提取的支票以及存款。

这是我的主要(我必须使用)

int main(void)
{
    char code;
    double amount, service, balance;
    double amtCheck, amtDeposit, openBalance, closeBalance;
    int numCheck, numDeposit;

    if (!(fpIn = fopen("account.txt", "r"))) {
        printf("account.txt could not be opened for input.");
        exit (1);
    }
    if (!(fpOut = fopen("csis.txt", "w"))) {
        printf("csis.txt could not be opened for output.");
        exit (1);
    }

    amount = 0.0;
    service = 0.0;
    balance = 0.0;
    amtCheck = 0.0;
    amtDeposit = 0.0;
    openBalance = 0.0;
    closeBalance = 0.0;
    numCheck = 0.0;
    numDeposit = 0.0;

    outputHeaders();

    while (!feof(fpIn)){
        fscanf(fpIn, "%c %lf\n", &code, &amount);
        if (code == 'I') {
            initialBalance(amount, &balance, &service, &openBalance);
        }
        else if (code == 'D'){
            deposit(amount, &balance, &service, &numDeposit, &amtDeposit);
        }
        else
        {
            check(amount, &balance, &service, &numCheck, &amtCheck);
        }
    }

    closeBalance = balance - service;
    outputSummary(numDeposit, amtDeposit, numCheck, amtCheck, openBalance,  service, closeBalance);
    fclose(fpIn);
    fclose(fpOut);
    return 0;

}


这是我的功能(必须使用)

void check(double amount, double *balance, double *service, int *numCheck, double *amtCheck)
{
    ++*numCheck;
    service = numCheck * 0.06;
    amtCheck += amount;
    balance -= amtCheck;
}


该服务是服务费,每张存入的支票为0.06美元。
numCheck用于提取支票的数量。
amtCheck是支票中提取的$的金额。
余额是月底所有提款的总计($)。

在功能(无效检查)中,我试图将numCheck * 0.06(服务= numCheck * 0.06)的产品分配给服务,并且由于某种原因,它不允许我这样做。以及尝试将amtCheck +金额的值分配给amtCheck(amtCheck + =金额),它也不允许我。正确的做法是什么?

(我也有其他功能来计算存款,但也有相同的问题)

最佳答案

使用指针值或为其分配值时,需要取消引用指针。
例如:

*service = (*numCheck)*0.06;

09-08 00:52