如何解决这是计算帐户余额的合适公式吗?当我运行代码时,我的最终余额是错误的
这是我到目前为止所拥有的。我还有更多工作要添加,但我现在想起余额计算器这个世界上的工作。我是新来的,但我做得更好。 (我认为)。我没有合适的方程式吗?
此代码的目的是在输入提款和存款后显示最终余额。由于某些原因,我的最终余额始终是我的初始余额。
//
// main.c
// accountbalance
//
//
//
#include <stdio.h>
int main()
{
float deposit[5];
float withdrawal[5];
float Curr_balance;
float Final_Bal;
int NumDep;
int NumWit;
printf("Welcome to the Computer Banking System!");
printf("\n\nEnter your current balance in dollars and cents: ");
scanf ("%f",&Curr_balance);
while (Curr_balance <0){
printf("\nBeginning balance must be at least zero,please re-enter.");
scanf ("%f",&Curr_balance);
}
printf ("\n\nEnter the number of deposits (0-5): ");
scanf ("%d",&NumDep);
while (NumDep > 5 || NumDep < 0){
printf ("Sorry,invalid number of deposits entered. Please try again");
scanf("%d",&NumDep);
}
printf ("\n\nEnter the number of withdrawals (0-5): ");
scanf ("%d",&NumWit);
while (NumWit > 5 || NumWit < 0){
printf ("Sorry,invalid number of withdrawals entered. Please try again");
scanf("%d",&NumWit);
}
int i;
for (i=0; i<NumDep; i++){
printf ("\n\nEnter the amount of deposit #%d: ",i+1);
scanf("%f",&deposit[i]);
if (deposit[i] <0)
{
printf ("Sorry,invalid number of deposits entered. Please try again ");
i = i -1;
continue;
}
}
int h;
for (h=0; h<NumWit; h++){
printf ("Enter the amount of withdrawal #%d: ",i+1);
scanf ("%f",&withdrawal[h]);
if (withdrawal[i]<0){
printf ("Withdrawal amount must be greater than zero,please try again");
i--;
continue;
}
else
{
}
}
Final_Bal = Curr_balance - NumDep + NumWit;
printf ("The closing balance is $%.2f",Curr_balance);
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。