Hi ppl,
This is my first post in CPROGRAMMIG.com
I have this program with me : Programme performing banking operation
Code:#include<stdio.h> #include<conio.h> void withdr(int acc,int n); void dep(int acc,int n); void bal(int acc,int n); struct bank { int acc; long int amt; }a[10]; void main() { int i,j,w1=0,temp,n,op,acc,amt; clrscr(); printf("\n Enter the number of acc numbers : "); scanf("%d",&n); for(i=0;i<n;i++) { w1=0; printf("\n Enter the acc number: "); scanf("%d",&temp); for(j=0;j<i;j++) { if(temp==a[j].acc) { w1=1; break; } } if(w1==1) { printf("\n Acc No already exist! "); i--; } else { a[i].acc=temp; printf("\n Enter the Amount: "); scanf("%ld",&a[i].amt); } } do { getch(); clrscr(); printf("\n Select the operation you want to perform: "); printf("\n 1.Balance \n 2.Withdraw \n 3.Deposit \n 4.Exit\n"); printf("Enter your Option:"); scanf("%d",&op); if(op!=4) { printf("\n Enter the acc no: "); scanf("%d",&acc); } switch(op) { case 1: withdr(acc,n); break; case 2: dep(acc,n); break; case 3: bal(acc,n); break; case 4: break; default:printf("\n Enter a value between 1 and 4"); } }while(op!=4); getch(); } void withdr(int acc,int n) { int w=0,i; for(i=0;i<n;i++) { if(acc==a[i].acc) { w=1; printf("\n The balance in the acc no %d is " "%d",a[i].acc,a[i].amt); } } if(w==0) printf("\n Wrong Account number! "); } void dep(int acc,int n) { int i=0,w=0,amt; for(i=0;i<n;i++) { if(acc==a[i].acc) { w=1; break; } } if(w==0) { printf("\n Wrong Account number! "); } else { if(a[i].amt-amt<0) printf("\n Negative Balance! "); else { printf("\n Enter the Amt you want to withdraw: "); scanf("%ld",&amt); a[i].amt=a[i].amt-amt; printf("\n %d Rs withdrawn ",amt); printf("\n New balance is: %ld",a[i].amt); } } } void bal(int acc,int n) { int i=0,w=0,amt; for(i=0;i<n;i++) if(acc==a[i].acc) { w=1; break; } if(w==0) printf("\n Wrong Account number! "); else { printf("\n Enter the amt you want to Deposit: "); scanf("%ld",&amt); a[i].amt=a[i].amt+amt; printf("\n %d Rs Deposited ",amt); printf("\n New balance is: %ld",a[i].amt); } }
This program can do only one operation per account ,i mean one account can perform only Withdraw money or deposit money or chk for balance .. if i try to withdraw ,after deposit .. it shows wrong account ..pls help me on this .. is loop needed for performing other operations? am very confused



LinkBack URL
About LinkBacks



This shouldn't be an obfuscation lesson here.