Mim527

bf

Aug 3rd, 2020 (edited)
2,566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.45 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. int i,j;
  5. int main_exit;
  6. void close();
  7. struct date
  8. {
  9.     int month,day,year;
  10.  
  11. };
  12. struct
  13. {
  14.  
  15.     char name[60];
  16.     int acc_no,age;
  17.     char address[60];
  18.     char citizenship[15];
  19.     double phone;
  20.     struct date dob;
  21.     struct date deposit;
  22.     struct date withdraw;
  23.  
  24. } add,check,rem;
  25.  
  26.  
  27. int main(){
  28.     int choice;
  29.     system("cls");
  30.     system("color 7");
  31.     printf("\n\n\t\t\t       BANKING MANAGEMENT SYSTEM");
  32.     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");
  33.     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:");
  34.     scanf("%d",&choice);
  35.  
  36.     system("cls");
  37.     switch(choice)
  38.     {
  39.     case 1:
  40.         new_acc();
  41.         break;
  42.     case 2:
  43.         see();
  44.         break;
  45.     case 3:
  46.         erase();
  47.         break;
  48.     case 4:
  49.         view_list();
  50.         break;
  51.     case 5:atm();
  52.         break;
  53.     case 6:
  54.         close();
  55.         break;
  56.     }
  57.  
  58.  
  59. return 0;
  60. }
  61. void new_acc()
  62.  
  63. {
  64.     int choice;
  65.     FILE *ptr;
  66.  
  67.     ptr=fopen("record.txt","a+");
  68. account_no:
  69.     system("cls");
  70.     printf("\t\t\t==== ADD RECORD  ====");
  71.     printf("\n\n\nEnter today's date(mm/dd/yyyy):");
  72.     scanf("%d/%d/%d",&add.deposit.month,&add.deposit.day,&add.deposit.year);
  73.     printf("\nEnter the account number:");
  74.     scanf("%d",&check.acc_no);
  75.     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)
  76.     {
  77.         if (check.acc_no==add.acc_no)
  78.         {
  79.             printf("Account no. already in use!");
  80.  
  81.             goto account_no;
  82.  
  83.         }
  84.     }
  85.     add.acc_no=check.acc_no;
  86.     printf("\nEnter the name:");
  87.     scanf("%s",add.name);
  88.     printf("\nEnter the date of birth(mm/dd/yyyy):");
  89.     scanf("%d/%d/%d",&add.dob.month,&add.dob.day,&add.dob.year);
  90.     printf("\nEnter the age:");
  91.     scanf("%d",&add.age);
  92.     printf("\nEnter the address:");
  93.     scanf("%s",add.address);
  94.     printf("\nEnter the citizenship number:");
  95.     scanf("%s",add.citizenship);
  96.     printf("\nEnter the phone number: ");
  97.     scanf("%lf",&add.phone);
  98.  
  99.  
  100.     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);
  101.  
  102.  
  103.     fclose(ptr);
  104.     printf("\nAccount created successfully!");
  105. add_invalid:
  106.     printf("\n\n\n\t\tEnter 1 to go to the main menu and 0 to exit:");
  107.     scanf("%d",&main_exit);
  108.     system("cls");
  109.     if (main_exit==1)
  110.         main();
  111.     else if(main_exit==0)
  112.         close();
  113.     else
  114.     {
  115.         printf("\nInvalid!\a");
  116.         goto add_invalid;
  117.     }
  118. }
  119. void view_list()
  120. {
  121.     FILE *view;
  122.     view=fopen("record.txt","r");
  123.     int test=0;
  124.     system("cls");
  125.     printf("\nACC. NO.\tNAME\t\t\tADDRESS\t\t\tPHONE\n");
  126.     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)
  127.     {
  128.         printf("\n%6d\t %10s\t\t\t%10s\t\t%lf",add.acc_no,add.name,add.address,add.phone);
  129.         test++;
  130.     }
  131.  
  132.     fclose(view);
  133.     if (test==0)
  134.     {
  135.         system("cls");
  136.         printf("\nNO RECORDS!!\n");
  137.     }
  138.  
  139. view_list_invalid:
  140.     printf("\n\nEnter 1 to go to the main menu and 0 to exit:");
  141.     scanf("%d",&main_exit);
  142.     system("cls");
  143.     if (main_exit==1)
  144.         main();
  145.     else if(main_exit==0)
  146.         close();
  147.     else
  148.     {
  149.         printf("\nInvalid!\a");
  150.         goto view_list_invalid;
  151.     }
  152. }
  153.  
  154. void erase()
  155. {
  156.     FILE *old,*newrec;
  157.     int test=0;
  158.     old=fopen("record.txt","r");
  159.     newrec=fopen("new.txt","w");
  160.     printf("Enter the account no. of the customer you want to delete:");
  161.     scanf("%d",&rem.acc_no);
  162.     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)
  163.     {
  164.  
  165.         if(add.acc_no!=rem.acc_no)
  166.             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);
  167.  
  168.         else
  169.         {
  170.             test++;
  171.             printf("\nRecord deleted successfully!\n");
  172.         }
  173.     }
  174.     fclose(old);
  175.     fclose(newrec);
  176.     remove("record.txt");
  177.     rename("new.txt","record.txt");
  178.     if(test==0)
  179.     {
  180.         printf("\nRecord not found!!\a\a\a");
  181. erase_invalid:
  182.         printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
  183.         scanf("%d",&main_exit);
  184.  
  185.         if (main_exit==1)
  186.             main();
  187.         else if (main_exit==2)
  188.             close();
  189.         else if(main_exit==0)
  190.             erase();
  191.         else
  192.         {
  193.             printf("\nInvalid!\a");
  194.             goto erase_invalid;
  195.         }
  196.     }
  197.     else
  198.     {
  199.         printf("\nEnter 1 to go to the main menu and 0 to exit:");
  200.         scanf("%d",&main_exit);
  201.         system("cls");
  202.         if (main_exit==1)
  203.             main();
  204.         else
  205.             close();
  206.     }
  207.  
  208. }
  209.  
  210. void see()
  211. {
  212.     FILE *ptr;
  213.     int test=0;
  214.     int choice;
  215.  
  216.     ptr=fopen("record.txt","r");
  217.     printf("Do you want to check by\n1.Account no\n2.Name\nEnter your choice:");
  218.     scanf("%d",&choice);
  219.     if (choice==1)
  220.     {
  221.         printf("Enter the account number:");
  222.         scanf("%d",&check.acc_no);
  223.         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)
  224.         {
  225.  
  226.             if(add.acc_no==check.acc_no)
  227.             {
  228.                 system("cls");
  229.                 test=1;
  230.  
  231.                 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,
  232.                        add.deposit.month,add.deposit.day,add.deposit.year);
  233.             }
  234.         }
  235.     }
  236.     else if (choice==2)
  237.     {
  238.         printf("Enter the name:");
  239.         scanf("%s",&check.name);
  240.         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)
  241.         {
  242.  
  243.             if(strcmpi(add.name,check.name)==0)
  244.             {
  245.                 system("cls");
  246.                 test=1;
  247.                 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,
  248.                        add.deposit.month,add.deposit.day,add.deposit.year);
  249.             }
  250.  
  251.         }
  252.     }
  253.  
  254.  
  255.     fclose(ptr);
  256.     if(test!=1)
  257.     {
  258.         system("cls");
  259.         printf("\nRecord not found!!\a\a\a");
  260. see_invalid:
  261.         printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
  262.         scanf("%d",&main_exit);
  263.         system("cls");
  264.         if (main_exit==1)
  265.             main();
  266.         else if (main_exit==2)
  267.             close();
  268.         else if(main_exit==0)
  269.             see();
  270.         else
  271.         {
  272.             system("cls");
  273.             printf("\nInvalid!\a");
  274.             goto see_invalid;
  275.         }
  276.     }
  277.     else
  278.     {
  279.         printf("\nEnter 1 to go to the main menu and 0 to exit:");
  280.         scanf("%d",&main_exit);
  281.     }
  282.     if (main_exit==1)
  283.     {
  284.         system("cls");
  285.         main();
  286.     }
  287.  
  288.     else
  289.     {
  290.  
  291.         system("cls");
  292.         close();
  293.     }
  294.  
  295. }
  296.  
  297.  
  298. void close(void)
  299. {
  300.     printf("\n\namr");
  301. }
  302.  
  303.  
  304.  
  305.  
  306. int atm(){
  307.     //Functions
  308.  
  309. void mainMenu();
  310. void checkBalance(float balance);
  311. float moneyDeposit(float balance);
  312. float moneyWithdraw(float balance);
  313. void menuExit();
  314. void errorMessage();
  315.  
  316. int login(void)
  317. {
  318.   float number = 1234;
  319.   int pass;
  320.   printf("\n\n\t\t\tEnter the PIN No:");
  321.   scanf("%d", &pass);
  322.  
  323.   if (pass == number)
  324.     {
  325.       printf("\n\nPIN Matched!\nLOADING");
  326.         for(i=0;i<=6;i++)
  327.         {
  328.  
  329.             printf(".");
  330.         }
  331.         system("cls");
  332.       mainMenu();
  333.     }
  334.   else
  335.     {
  336.       printf("Invalid\n Try Again");
  337.       login();
  338.     }
  339.   return 0;
  340. }
  341.  
  342.  
  343. //Main Code
  344.         //Local Declarations
  345.     int option;
  346.     float balance = 15000.00;
  347.     int choose;
  348.  
  349.  
  350.     // insert code here...
  351.     login();
  352.     while (1) {
  353.     printf("Your Selection:\t");
  354.     scanf("%d", &option);
  355.      system("CLS");
  356.  
  357.         switch (option) {
  358.             case 1:
  359.                 checkBalance(balance);
  360.                 break;
  361.             case 2:
  362.                 balance = moneyDeposit(balance);
  363.                 break;
  364.             case 3:
  365.                 balance = moneyWithdraw(balance);
  366.                 break;
  367.             case 4:
  368.                 menuExit();
  369.                 return 0;
  370.  
  371.             default:
  372.                 errorMessage();
  373.                 break;
  374.         }
  375.             mainMenu();
  376.  
  377.  
  378. }
  379.  
  380.  
  381.     return 0;
  382.  
  383. }//main code
  384.  
  385.  
  386.  
  387. //Functions
  388.  
  389. void mainMenu() {
  390.  
  391.     printf("\n\n\t\t==========Welcome to ATM Feature==========\n\n");
  392.     printf("\n\t\t----Please choose one of the options below----\n");
  393.     printf("\n\t\t< 1 >  Check Balance\n");
  394.     printf("\n\t\t< 2 >  Deposit\n");
  395.     printf("\n\t\t< 3 >  Withdraw\n");
  396.     printf("\n\t\t< 4 >  Exit\n\n");
  397.  
  398. }//Main Menu
  399.  
  400. void checkBalance(float balance) {
  401.     printf("You Choose to See your Balance\n");
  402.     printf("****Your Available Balance is:   $%.2f\n\n", balance);
  403.  
  404. }//Check Balance
  405.  
  406. float moneyDeposit(float balance) {
  407.     float deposit;
  408.     printf("$$$$Your Balance is: $%.2f\n\n", balance);
  409.     printf("****Enter your amount to Deposit\n");
  410.     scanf("%f", &deposit);
  411.  
  412.  
  413.     balance += deposit;
  414.  
  415.     printf("****Your New Balance is:   $%.2f\n\n", balance);
  416.     return balance;
  417.  
  418.  
  419. }//money deposit
  420.  
  421. float moneyWithdraw(float balance) {
  422.     float withdraw;
  423.  
  424.     printf("You choose to Withdraw a money\n");
  425.     printf("$$$$Your Balance is: $%.2f\n\n", balance);
  426.  
  427.  
  428.     printf("Enter your amount to withdraw:\n");
  429.     scanf("%f", &withdraw);
  430.  
  431.  
  432.     if (withdraw < balance) {
  433.  
  434.         balance -= withdraw;
  435.         printf("$$$$Your withdrawing money is:  $%.2f\n", withdraw);
  436.         printf("****Your New Balance is:   $%.2f\n\n", balance);
  437.  
  438.     }
  439.  
  440.         else  {
  441.  
  442.         printf("+++You don't have enough money+++\n");
  443.         printf("****Your Balance is:   $%.2f\n\n", balance);
  444.  
  445.     }
  446.  
  447.     return balance;
  448.  
  449.  
  450. }
  451.  
  452.  
  453. void menuExit()
  454. {
  455.     printf("--------------Take your receipt!!!------------------\n");
  456.     printf("-----Thank you for using ATM Banking Machine!!!-----\n");
  457.  
  458.  
  459.  
  460. }//exit menu
  461.  
  462. void errorMessage()
  463. {
  464.     ;
  465.     printf("+++!!!You selected invalid number!!!+++\n");
  466. }
  467.  
  468.  
Advertisement
Add Comment
Please, Sign In to add comment