【发布时间】: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() 函数,除了我减去因为它是取款吗?