这是计算帐户余额的合适公式吗?当我运行代码时,我的最终余额是错误的

时间:2020-10-16 21:05:03

标签: c calculator

这是我到目前为止所拥有的。我还有更多工作要添加,但我现在想起余额计算器这个世界上的工作。我是新来的,但我做得更好。 (我认为)。我没有合适的方程式吗?

此代码的目的是在输入提款和存款后显示最终余额。由于某些原因,我的最终余额始终是我的初始余额。

//
//  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;
}

0 个答案:

没有答案