Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int i,j;
- int main_exit;
- void close();
- struct date
- {
- int month,day,year;
- };
- struct
- {
- char name[60];
- int acc_no,age;
- char address[60];
- char citizenship[15];
- double phone;
- struct date dob;
- struct date deposit;
- struct date withdraw;
- } add,check,rem;
- int main(){
- int choice;
- system("cls");
- system("color 7");
- printf("\n\n\t\t\t BANKING MANAGEMENT SYSTEM");
- printf("\n\n\n\t\t\t\xB2\xB2\xB2\xB2\xB2\xB2\xB2 WELCOME TO THE MAIN MENU \xB2\xB2\xB2\xB2\xB2\xB2\xB2");
- printf("\n\n\t\t[1] Create a new account\n\t\t[2] Check the details of existing account\n\t\t[3] Remove existing account\n\t\t[4] View customer's list\n\t\t[5] ATM Feature\n\t\t[6] Exit\n\n\n\t\t Enter your choice:");
- scanf("%d",&choice);
- system("cls");
- switch(choice)
- {
- case 1:
- new_acc();
- break;
- case 2:
- see();
- break;
- case 3:
- erase();
- break;
- case 4:
- view_list();
- break;
- case 5:atm();
- break;
- case 6:
- close();
- break;
- }
- return 0;
- }
- void new_acc()
- {
- int choice;
- FILE *ptr;
- ptr=fopen("record.txt","a+");
- account_no:
- system("cls");
- printf("\t\t\t==== ADD RECORD ====");
- printf("\n\n\nEnter 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 %d %lf %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.deposit.month,&add.deposit.day,&add.deposit.year)!=EOF)
- {
- if (check.acc_no==add.acc_no)
- {
- printf("Account no. already in use!");
- goto account_no;
- }
- }
- add.acc_no=check.acc_no;
- printf("\nEnter the name:");
- scanf("%s",add.name);
- printf("\nEnter the date of birth(mm/dd/yyyy):");
- scanf("%d/%d/%d",&add.dob.month,&add.dob.day,&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);
- fprintf(ptr,"%d %s %d/%d/%d %d %s %d %lf %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.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 the main menu and 0 to exit:");
- scanf("%d",&main_exit);
- system("cls");
- if (main_exit==1)
- main();
- else if(main_exit==0)
- close();
- else
- {
- printf("\nInvalid!\a");
- goto add_invalid;
- }
- }
- void view_list()
- {
- FILE *view;
- view=fopen("record.txt","r");
- int test=0;
- system("cls");
- printf("\nACC. NO.\tNAME\t\t\tADDRESS\t\t\tPHONE\n");
- while(fscanf(view,"%d %s %d/%d/%d %d %s %d %lf %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.deposit.month,&add.deposit.day,&add.deposit.year)!=EOF)
- {
- printf("\n%6d\t %10s\t\t\t%10s\t\t%lf",add.acc_no,add.name,add.address,add.phone);
- test++;
- }
- fclose(view);
- if (test==0)
- {
- system("cls");
- printf("\nNO RECORDS!!\n");
- }
- view_list_invalid:
- printf("\n\nEnter 1 to go to the main menu and 0 to exit:");
- scanf("%d",&main_exit);
- system("cls");
- if (main_exit==1)
- main();
- else if(main_exit==0)
- close();
- else
- {
- printf("\nInvalid!\a");
- goto view_list_invalid;
- }
- }
- void erase()
- {
- FILE *old,*newrec;
- int test=0;
- old=fopen("record.txt","r");
- newrec=fopen("new.txt","w");
- printf("Enter the account no. of the customer you want to delete:");
- scanf("%d",&rem.acc_no);
- while(fscanf(old,"%d %s %d/%d/%d %d %s %d %lf %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.deposit.month,&add.deposit.day,&add.deposit.year)!=EOF)
- {
- if(add.acc_no!=rem.acc_no)
- fprintf(newrec,"%d %s %d/%d/%d %d %s %d %lf %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.deposit.month,add.deposit.day,add.deposit.year);
- else
- {
- test++;
- printf("\nRecord deleted successfully!\n");
- }
- }
- fclose(old);
- fclose(newrec);
- remove("record.txt");
- rename("new.txt","record.txt");
- if(test==0)
- {
- printf("\nRecord not found!!\a\a\a");
- erase_invalid:
- printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
- scanf("%d",&main_exit);
- if (main_exit==1)
- main();
- else if (main_exit==2)
- close();
- else if(main_exit==0)
- erase();
- else
- {
- printf("\nInvalid!\a");
- goto erase_invalid;
- }
- }
- else
- {
- printf("\nEnter 1 to go to the main menu and 0 to exit:");
- scanf("%d",&main_exit);
- system("cls");
- if (main_exit==1)
- main();
- else
- close();
- }
- }
- void see()
- {
- FILE *ptr;
- int test=0;
- int choice;
- ptr=fopen("record.txt","r");
- printf("Do you want to check by\n1.Account no\n2.Name\nEnter your choice:");
- scanf("%d",&choice);
- if (choice==1)
- {
- printf("Enter the account number:");
- scanf("%d",&check.acc_no);
- while(fscanf(ptr,"%d %s %d/%d/%d %d %s %d %lf %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.deposit.month,&add.deposit.day,&add.deposit.year)!=EOF)
- {
- if(add.acc_no==check.acc_no)
- {
- system("cls");
- test=1;
- printf("\nAccount NO.:%d\nName:%s \nDOB:%d/%d/%d \nAge:%d \nAddress:%s \nCitizenship No:%s \nPhone number:%.0lf\n\nDate Of Deposit:%d/%d/%d\n\n",add.acc_no,add.name,add.dob.month,add.dob.day,add.dob.year,add.age,add.address,add.citizenship,add.phone,
- add.deposit.month,add.deposit.day,add.deposit.year);
- }
- }
- }
- else if (choice==2)
- {
- printf("Enter the name:");
- scanf("%s",&check.name);
- while(fscanf(ptr,"%d %s %d/%d/%d %d %s %d %lf %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.deposit.month,&add.deposit.day,&add.deposit.year)!=EOF)
- {
- if(strcmpi(add.name,check.name)==0)
- {
- system("cls");
- test=1;
- printf("\nAccount No.:%d\nName:%s \nDOB:%d/%d/%d \nAge:%d \nAddress:%s \nCitizenship No:%s \nPhone number:%.0lf\nDate Of Deposit:%d/%d/%d\n\n",add.acc_no,add.name,add.dob.month,add.dob.day,add.dob.year,add.age,add.address,add.citizenship,add.phone,
- add.deposit.month,add.deposit.day,add.deposit.year);
- }
- }
- }
- fclose(ptr);
- if(test!=1)
- {
- system("cls");
- printf("\nRecord not found!!\a\a\a");
- see_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)
- main();
- else if (main_exit==2)
- close();
- else if(main_exit==0)
- see();
- else
- {
- system("cls");
- printf("\nInvalid!\a");
- goto see_invalid;
- }
- }
- else
- {
- printf("\nEnter 1 to go to the main menu and 0 to exit:");
- scanf("%d",&main_exit);
- }
- if (main_exit==1)
- {
- system("cls");
- main();
- }
- else
- {
- system("cls");
- close();
- }
- }
- void close(void)
- {
- printf("\n\namr");
- }
- int atm(){
- //Functions
- void mainMenu();
- void checkBalance(float balance);
- float moneyDeposit(float balance);
- float moneyWithdraw(float balance);
- void menuExit();
- void errorMessage();
- int login(void)
- {
- float number = 1234;
- int pass;
- printf("\n\n\t\t\tEnter the PIN No:");
- scanf("%d", &pass);
- if (pass == number)
- {
- printf("\n\nPIN Matched!\nLOADING");
- for(i=0;i<=6;i++)
- {
- printf(".");
- }
- system("cls");
- mainMenu();
- }
- else
- {
- printf("Invalid\n Try Again");
- login();
- }
- return 0;
- }
- //Main Code
- //Local Declarations
- int option;
- float balance = 15000.00;
- int choose;
- // insert code here...
- login();
- while (1) {
- printf("Your Selection:\t");
- scanf("%d", &option);
- system("CLS");
- switch (option) {
- case 1:
- checkBalance(balance);
- break;
- case 2:
- balance = moneyDeposit(balance);
- break;
- case 3:
- balance = moneyWithdraw(balance);
- break;
- case 4:
- menuExit();
- return 0;
- default:
- errorMessage();
- break;
- }
- mainMenu();
- }
- return 0;
- }//main code
- //Functions
- void mainMenu() {
- printf("\n\n\t\t==========Welcome to ATM Feature==========\n\n");
- printf("\n\t\t----Please choose one of the options below----\n");
- printf("\n\t\t< 1 > Check Balance\n");
- printf("\n\t\t< 2 > Deposit\n");
- printf("\n\t\t< 3 > Withdraw\n");
- printf("\n\t\t< 4 > Exit\n\n");
- }//Main Menu
- void checkBalance(float balance) {
- printf("You Choose to See your Balance\n");
- printf("****Your Available Balance is: $%.2f\n\n", balance);
- }//Check Balance
- float moneyDeposit(float balance) {
- float deposit;
- printf("$$$$Your Balance is: $%.2f\n\n", balance);
- printf("****Enter your amount to Deposit\n");
- scanf("%f", &deposit);
- balance += deposit;
- printf("****Your New Balance is: $%.2f\n\n", balance);
- return balance;
- }//money deposit
- float moneyWithdraw(float balance) {
- float withdraw;
- printf("You choose to Withdraw a money\n");
- printf("$$$$Your Balance is: $%.2f\n\n", balance);
- printf("Enter your amount to withdraw:\n");
- scanf("%f", &withdraw);
- if (withdraw < balance) {
- balance -= withdraw;
- printf("$$$$Your withdrawing money is: $%.2f\n", withdraw);
- printf("****Your New Balance is: $%.2f\n\n", balance);
- }
- else {
- printf("+++You don't have enough money+++\n");
- printf("****Your Balance is: $%.2f\n\n", balance);
- }
- return balance;
- }
- void menuExit()
- {
- printf("--------------Take your receipt!!!------------------\n");
- printf("-----Thank you for using ATM Banking Machine!!!-----\n");
- }//exit menu
- void errorMessage()
- {
- ;
- printf("+++!!!You selected invalid number!!!+++\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment