Hello, iam making a atm to calculate some items. in the program i ask for a deposit and it does show. Then i as for balance which does show but at2x the variable i put in. I really have no clue as to what is causing the variable to multiple by 2 when i as for it to be seen in the account balance option.
only account chequing is done for now so use that instead of savings. I cheacked my code long and i cant figure out what the problem is, any insight would be helpfull.Code:#include<stdio.h> #include<math.h> int chooseaccounttype(void); float Compound(float,int); main() { char select; float deposit=0,withdraw=0,sum1=0,sum2=0,interest=0; int accountchoice,months; do{ printf("\n\n\n\ta) Deposit"); printf("\n\tb) Withdraw"); printf("\n\tc) Add Interest"); printf("\n\td) Account Balance"); printf("\n\te) Exit"); printf("\n\n\tPlease select one of the choices above (a -> e)"); fflush(stdin); scanf("%c",&select); getchar(); system("cls"); switch (select) { case 'A': case 'a': printf("\n\n\tenter amount to deposit-->"); fflush(stdin); scanf("%f",&deposit); fflush(stdin); system("cls"); accountchoice=chooseaccounttype(); printf("You deposited $ %.2f",deposit); getch(); system("cls"); break; case 'B': case 'b': printf("enter amount to withdraw"); scanf("%f",&withdraw); system("cls"); accountchoice=chooseaccounttype(); break; case 'C': case 'c': printf("Enter the interest"); scanf("%f",&interest); printf("\n Enter the amount of months"); scanf("%i",&months); accountchoice=chooseaccounttype(); getch(); break; case 'D': case 'd': accountchoice=chooseaccounttype(); break; case 'E': case 'e': printf("last check"); getch(); break; default: printf("\tinvalid Selection"); getch(); system("cls"); break; } switch(accountchoice) { case 1: if(select=='a'||'A') { sum1= sum1+deposit; printf("Your new balance is %.2f",sum1); } else if(select=='b'||'B') if(sum1<withdraw) { printf("Insuffient funds"); } else if(sum1>=withdraw) { sum1=sum1-withdraw; fflush(stdin); printf("your new balance is %.2f",sum1); fflush(stdin); } else if(select=='c'||'C') { } else { printf("u have %f",sum1); getch(); } break; case 2: puts (" savings"); break; } }while(select!='e' && select!='E'); } int chooseaccounttype(void) { int account; printf("\n\t\t1) Chequing"); printf("\n\t\t2) Savings"); printf("\n Please select the account type:"); fflush(stdin); scanf("%i",&account); switch(account) { case 1: return(1); break; case 2: return(2); break; } }



LinkBack URL
About LinkBacks


