Code:
#include<stdio.h>#include<stdlib.h>
#include<windows.h>
int i,j;
int main_exit;
//void menu();
struct date{
int month,day,year;
};
struct{
char name[60];
int acc_no,age;
char address[60];
char citizenship[15];
double phone;
char acc_type[10];
float amt;
struct date dob;
struct date deposit;
struct date withdraw;
}add,upd,check,rem,transaction;
//interest function
float interest(float t,float amount,int rate)
{
float SI;
SI = (rate*t*amount)/100;
return (SI);
}
//delay function
void fordelay(int j)
{
int i,k;
for(i=0;i<j;i++)
{
k = i;
}
}
//new account
void new_acc()
{
int choice;
FILE *ptr;
ptr = fopen("record.dat","a+");
account_no:
system("cls");
printf("\t\t\t\xB2\xB2\xB2\ ADD RECORD \xB2\xB2\xB2\xB2");
printf("Enter Today's Date(mm/dd/yyyy: ");
scanf("%d/%d/%d",&add.deposit.month,&add.deposit.day,&add.deposit.year);
printf("\nEnter the account number:");
scanf("%d",&check.acc_no);
while(fscanf(ptr,"%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d\n",&add.acc_no,add.name,&add.dob.month,&add.dob.day,&add.dob.year,&add.age,add.address,add.citizenship,&add.phone,add.acc_type,&add.amt,&add.deposit.month,&add.deposit.day,&add.deposit.year)!=EOF)
{
if(check.acc_no = add.acc_no)
{
printf("Account no. already in use!");
fordelay(1000000000);
goto account_no;
}
}
add.acc_no = check.acc_no;
printf("Enter the name: ");
scanf("%s",add.name);
printf("Enter the date of birth(mm/dd/yyyy): ");
scanf("%d/%d/%d",&add.dob.month,&add.dob.year,&add.dob.year);
printf("\nEnter the age: ");
scanf("%d",&add.age);
printf("\nEnter the address: ");
scanf("%s",add.address);
printf("\nEnter the citizenship number: ");
scanf("%s",add.citizenship);
printf("\nEnter the phone number: ");
scanf("%lf",&add.phone);
printf("\nEnter the amount to deposit: ");
scanf("%f",&add.amt);
printf("\nType of account:\n\t#Savings\n\t#Current\n\t#Fixed(for 1 year)\n\t#Fixed(for 2 years)\n\t#Fixed(for 3 years)\n\n\tEnter your choice:");
scanf("%s",add.acc_type);
fprintf(ptr,"%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d\n",add.acc_no,add.name,add.dob.month,add.dob.day,add.dob.year,add.age,add.address,add.citizenship,add.phone,add.acc_type,add.amt,add.deposit.month,add.deposit.day,add.deposit.year);
fclose(ptr);
printf("\nAccount created successfully!");
add_invalid:
printf("\n\n\n\t\tEnter 1 to go to main menu and 0 to exit: ");
scanf("%d",&main_exit);
system("cls");
if(main_exit==1)
{
menu();
}
else if(main_exit==0)
{
close();
}
else
{
printf("\nInvalid!\a");
goto add_invalid;
}
}
//edit account
void edit()
{
int choice,test= 0;
FILE *old,*newrec;
old = fopen("record.dat","r");
newrec = fopen("new.dat","w");
printf("\nEnter the account no. of customer whose info you want to change:");
scanf("%d",&upd.acc_no);
while(fscanf(old,"%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d",&add.acc_no,add.name,&add.dob.month,&add.dob.day,&add.dob.year,&add.age,add.address,add.citizenship,&add.phone,add.acc_type,&add.amt,&add.deposit.month,&add.deposit.day,&add.deposit.year)!=EOF)
{
if(add.acc_no == upd.acc_no)
{
test = 1;
printf("\nWhich information do you want to change?\n1.Address\n2.phone\n\nEnter your choice(1 for address and 2 for phone):");
scanf("%d",&choice);
system("cls");
if(choice==1)
{
printf("Enter the new address:");
scanf("%d",upd.address);
fprintf(newrec,"%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d\n",add.acc_no,add.name,add.dob.month,add.dob.day,add.dob.year,add.age,upd.address,add.citizenship,add.phone,add.acc_type,add.amt,add.deposit.month,add.deposit.day,add.deposit.year);
system("cls");
printf("Changes saved!");
}
else if(choice ==2)
{
printf("Enter the new phone number:");
scanf("%lf",&upd.phone);
fprintf(newrec,"%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d\n",add.acc_no,add.name,add.dob.month,add.dob.day,add.dob.year,add.age,add.address,add.citizenship,upd.phone,add.acc_type,add.amt,add.deposit.month,add.deposit.day,add.deposit.year);
system("cls");
printf("Changes saved!");
}
}
else
{
fprintf(newrec,"%d %s %d/%d/%d %d %s %s %lf %s %f %d/%d/%d\n",add.acc_no,add.name,add.dob.month,add.dob.day,add.dob.year,add.age,add.address,add.citizenship,add.phone,add.acc_type,add.amt,add.deposit.month,add.deposit.day,add.deposit.year);
}
}
fclose(old);
fclose(newrec);
remove("record.dat");
rename("new.dat","record.dat");
if(test!=1)
{
system("cls");
printf("\nRecord not found!!\a\a\a");
edit_invalid:
printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
scanf("%d",&main_exit);
system("cls");
if(main_exit==1)
{
menu();
}
else if(main_exit==2)
{
close();
}
else
{
printf("\nInvalid !\a");
goto edit_invalid;
}
}
else
{
printf("\n\n\nEnter 1 to go to main menu and 0 to exit:");
scanf("%d",&main_exit);
system("cls");
if(main_exit==1)
{
menu();
}
else
{
close();
}
}
}
//Close function
void close()
{
printf("\n\n\nThis C project is developed by Code with C Team!");
}
//menu function
void menu()
{
int choice;
system("cls");
system("color 9");
printf("\n\n\t\t\tCUSTOMER ACCOUNT BANKING MANAGEMENT SYSTEM");
printf("\n\n\n\t\t\t\xB2\xB2\xB2\xB2\xB2\xB2\xB2 WELCOME TO MAIN MENU \xB2\xB2\xB2\xB2\xB2\xB2\xB2");
printf("\n\n\t\t1.Create new account\n\t\t2.Update account\n\t\t3.For transactions\n\t\t4.Checking details of existing account\n\t\t5.Closing existing account\n\t\t6.View Customer's list\n\t\t7.Exit\n\n\n\n\n\t\tEnter your choice:");
scanf("%d",&choice);
system("cls");
switch(choice)
{
case 1:
new_acc();
break;
case 2:
edit();
break;
}
}
int main()
{
//new_acc();
menu();
return 0;
}
there is also another issue i noticed when i try to edit existing account the whole record is getting wiped out