You are on page 1of 4

//Prog to create structure for bank

#include<stdio.h>
#include<conio.h>

void main()
{
struct Bank
{
int accno;
char name[20];
char acctype[20];
int opbal;
}b[50];

struct Bank temp;

int i=0,choice;
char ans;
clrscr();
while(1) //infinite loop
{
printf("\n======================Bank
Management=======================\n");
printf("1. Open New Account \n");
printf("2. List All Accounts \n");
printf("3. Search Account Details \n");
printf("4. Update Account (Withdraw / Deposit)\n");
printf("5. Sort by balance\n");
printf("6. Exit \n");

printf("Enter your choice \n");


scanf("%d",&choice);

switch(choice)
{
case 1:
{
do
{
printf("Enter account no \n");
scanf("%d",&b[i].accno);
printf("Enter holder's name \n");
scanf("%s",&b[i].name);
printf("Enter account type \n");
scanf("%s",&b[i].acctype);
printf("Enter opening balance \n");
scanf("%d",&b[i].opbal);
i++;
printf("Add more records \n");
flushall();
scanf("%c",&ans);
}
while(ans=='y');
break;
}

case 2:
{
int j;
printf("Account no \t Holder's name \t Account type \t Opening balance
\n");

printf("----------------------------------------------------------------\n");
for(j=0;j<i;j++)
{
printf("%3d \t\t %-10s \t %-10s \t %4d
\n",b[j].accno,b[j].name,b[j].acctype,b[j].opbal);
}

printf("------------------------------------------------------------------\n");
break;
}

case 3:
{
int taccno;
int flag,j;
printf("Enter account no for search \n");
scanf("%d",&taccno);
for(j=0;j<i;j++)
{
if(taccno==b[j].accno)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag==1)
{
printf("Record found......\n");
printf("Account details are.....\n");
printf("%3d \t %-10s \t %-10s \t %4d
\n",b[j].accno,b[j].name,b[j].acctype,b[j].opbal);
}
else
printf("Record not found......\n");
break;
}

case 4:
{
int taccno;
int flag,j,amt;
char ch;
printf("Enter account no for search \n");
scanf("%d",&taccno);
for(j=0;j<i;j++)
{
if(taccno==b[j].accno)
{
flag=1;
break;
}
else
{
flag=0;
}
}
if(flag==1)
{
printf("Record found......\n");
printf("Account details are.....\n");
printf("%3d \t %-10s \t %-10s \t %4d
\n",b[j].accno,b[j].name,b[j].acctype,b[j].opbal);
printf("Enter how much amount \n");
scanf("%d",&amt);
printf("Enter type of transaction(D-deposit or W-withdraw) \n");
flushall();
scanf("%c",&ch);
switch(ch)
{
case 'W':
{
if(amt > b[j].opbal)
{
printf("Insufficient balance...... \n");
printf("You can withdraw only %d amount \n",b[j].opbal);
break;
}
else
{
b[j].opbal -= amt;
printf("Balance is debited....\n");
}
break;
}

case 'D':
{
b[j].opbal += amt;
printf("Balance is credited......\n");
break;
}
}
}
else
printf("Record not found......\n");
break;
}

case 5:
{
//sorting
int j,k;
for(j=0;j<i;j++)
{
for(k=j+1;k<i;k++)
{
if(b[j].opbal > b[k].opbal)
{
temp = b[j];
b[j] = b[k];
b[k] = temp;
}
}
}
break;
}

case 6:
{
exit(0);
}
}
}
getch();
}

You might also like