【问题标题】:deposit() function of this checking account C program此支票账户 C 程序的 deposit() 函数
【发布时间】:2015-10-16 05:13:19
【问题描述】:

我正在用 C 语言编写一个程序来模拟支票账户。有交易代码,I = 初始余额,D = 存款,C = 支票(你给某人写一张支票,就像取款一样)。维护帐户的月费为 3.00 美元,兑现每张支票的费用为 0.06 美元,每笔存款 %0.03,当兑现支票余额低于 0.00 美元时,透支费用为 5.00 美元。

我无法完成这些功能。如果您不认为对所有这些都提供一点帮助是可以的,那么请帮助使用 deposit() 函数。我才刚接触 C 语言几个月,而我们刚刚接触到函数。这是我未完成的代码。感谢您的帮助。

#include <stdio.h>

void outputHeaders (void);
void initialBalance (double iBalance);
void deposit(double amount, double balance, double service, int numDeposit,double amtDeposit);
void check(char code, double amtCheck, double balance);
void outputSummary ();


int main (void)
{

char code;
double amount, service, balance;
double amtCheck, amtDeposit, openBalance, closeBalance;
int numCheck, numDeposit;

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

outputHeaders();

printf("Enter the code of transaction and the amount: ");
scanf("%c %lf\n", &code, &amount);

if (code == 'I')
{
    initialBalance(amount, &balance, &service, &numDeposit, &amtDeposit);
}

else if (code == 'D')
{
    deposit (amount, &balance, &service, &numDeposit);  
}
else
{
    check(amount, &balance, &service, &numCheck, &amtCheck);
}


getchar(); getchar();
return 0;
}

void outputHeaders (void)
{

printf("Transaction         Deposit       Check      Balance\n"
       "--------------      --------      ------     -------");
}

void initialBalance (double amount, double *balance, double *service, int *numDeposit, double *amtDeposit)
{



}

void deposit (double amount, double *balance, double *service, int *numDeposit, double *amtDeposit)
{

*balance = *balance + *amtDeposit;  
*numDeposit++;                      //need to keep track of amount of deposits
*service = *service - 0.03;         //service charge

printf("Deposit %lf %lf\n", *amtDeposit, *balance);

}

void check (double amount, double *balance, double *service, int *numCheck, double *amtCheck)
{



}

void outputSummary (int *numDeposit, double *amtDeposit, int *numCheck, int *amtCheck, double *openBalance, double *service, double *closeBalance)
{



}

【问题讨论】:

  • I am having trouble completing the functions. 告诉我们问题出在哪里。 “我不知道 C”超出了 SO 的范围。
  • @John3136 抱歉,如果不清楚,但我确实就存款功能寻求帮助。我有正确的吗?该代码是否会适当地更新余额,以便将其用于其他交易?
  • @Futbolero 您在deposit() 函数中面临的问题是什么?
  • @Pawan 我想知道我所做的是否正确。代码是否会适当地更新余额,以便新的余额可用于未来的交易?不知道如何测试它,所以我在问,所以如果我看错了,也许有更多知识和经验的人可以纠正我。如果它是正确的,我可以以相同的方式执行 check() 函数,除了我减去因为它是取款吗?

标签: c function account bank


【解决方案1】:

当您声明/定义时,我只看到deposit(); 函数在您的函数中,您使用了五个参数,但调用时间只使用了四个参数。

所以如果你打电话给deposit (amount, &amp;balance, &amp;service, &amp;numDeposit);

然后像这样更改您的定义/声明

void deposit (double amount, double *balance, double *service, int *numDeposit)
{

*balance = *balance + amount;  
*numDeposit++;                      //need to keep track of amount of deposits
*service = *service - 0.03;         //service charge
//I think service change need to reduce from main balance so
*balance = *balance - 0.03;
printf("Deposit %lf  balance %lf\n", amount, *balance);

}

【讨论】:

  • @Futbolero 你进步了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
  • 2021-07-03
  • 2019-11-15
  • 1970-01-01
  • 2018-08-06
  • 1970-01-01
  • 2014-12-02
相关资源
最近更新 更多