Guest User

Bankaccount(feb 16,2014)

a guest
Feb 17th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.50 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>               //HEADER FILES
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <Windows.h>
  6.  
  7.  
  8.  void display_main_menu();
  9.  void create_account();
  10.  void modify_account();      //FUNCTION DECLARATIONS
  11.  void make_withdrawal();
  12.  void make_deposit();
  13.  void make_donation();
  14.  void logo();
  15.  
  16.  
  17.  FILE *acc;                  //FILE DECLARATION
  18.  
  19. typedef struct
  20. {
  21.     char firstname[20];      //STRUCTURE
  22.     char lastname[20];
  23.     int payment_type=0;
  24.     int age_calculation;
  25.     int yob;
  26.     char password[30];
  27.     char parish[20];
  28.     float acc_bal=0;
  29.     float acc_fee=0;
  30.     float acc_change=0;
  31.     float withdraw_change=0;
  32.     float account_num;
  33. }accounts;
  34.  
  35.  accounts students;
  36.  
  37.  
  38. main()                  //MAIN STARTS HERE
  39. {
  40.     SetConsoleTitle("Program done by Nicholas Cameron...Banking Agency");
  41.     int program_pass=2014; //Password needed to access the program
  42.     int pass=0;
  43.     char option;
  44.     float deposit;
  45.     float sav_bal,cur_bal;//for deposit process;
  46.  
  47.  
  48.      logo();
  49.     do  //CODES FOR ENETRING THE PASSWORD
  50.      {
  51.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  52.                  printf("Enter password ");
  53.                  scanf("%d", &pass);
  54.                  fflush(stdin);
  55.                  if(pass!=program_pass)
  56.                  printf("\nAccess Denied! \nPassword incorrect. Please try again ");
  57.      }
  58.                 while (pass!=program_pass);
  59.  
  60.  
  61.                 while (pass==program_pass)  // while loop for when password entered is correct
  62.                 {
  63.                     printf(" \nAccess Granted!\n");
  64.                     printf("\n\nPress enter to continue");
  65.                             getch();
  66.                             system("cls");
  67.                             display_main_menu();
  68.                 }
  69.  
  70.  
  71.  
  72. system("pause");
  73. exit(1);
  74. }//MAIN ENDS HERE
  75.  
  76.  
  77.  
  78.  
  79. //FUNCTION DEFINITIONS
  80. void display_main_menu()     //function display main menu
  81. {
  82.     main_menu:        // goto LABEL FOR MAIN MENU
  83.     system("cls");
  84.     char activity_selection;
  85.     logo();
  86.  
  87. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  88. printf("Please select from the list below the action you wish to carry out\n\n\t");
  89.  
  90. printf("     || A. Create an account -(Preferably for new users) ||\n\t");
  91. printf("     || B. Make a deposit    -(for members only)         ||\n\t");
  92. printf("     || C. Make a withdrawal -(for members only)         ||\n\t");
  93. printf("     || D. Modify an account -(for members only)         ||\n\t");
  94. printf("     || E. Make a Donation   -(for members only)         ||\n\n");
  95. printf("Enter the letter that corresponds with each option\n");
  96. scanf("%s",&activity_selection);
  97. system("cls");
  98. switch(activity_selection)
  99. {
  100.     case 'A': case'a':
  101.     create_account();
  102.     break;
  103.  
  104.     case 'B': case 'b': //DEPOSIT PROCESS
  105.     make_deposit();
  106.     break;
  107.  
  108.     case 'C': case 'c': //WITHDRAWAL PROCESS
  109.     make_withdrawal();
  110.     break;
  111.  
  112.  
  113.     case 'D': case 'd': //Modifying PROCESS
  114.         modify_account();
  115.     break;
  116.  
  117.     case 'E': case 'e': //DONATION PROCESS
  118.         make_donation();
  119.  
  120.     default :
  121.         system("cls");
  122.     printf("The choice you entered appears to be invalid\n");
  123.             SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
  124.     printf("\n\t      ||                A.<MAIN MENU>            ||\n\t");
  125.     printf("      ||                B.<EXIT>                 ||\n\n");
  126.  
  127.      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  128.     printf("Please enter the corresponding letter for the task you wish to execute\n\n\n");
  129.     scanf("%s",&activity_selection);
  130.  
  131.     if(activity_selection=='A'||activity_selection=='a')
  132.     {
  133.         goto main_menu; //THIS MOVES TO THE MAIN MENU IF 'A' OR 'a' IS ENTERED.DIDNT CALL THE display_main_menu() FUNCTION SINCE WE'RE ALREADY INSIDE IT
  134.     }
  135.     else if(activity_selection=='B'||activity_selection=='b')
  136.     {
  137.         exit(1);  //Exits the program if exit is selected
  138.     }
  139.     else
  140.     {
  141.         printf("Another invalid answer option entered.Thank you for trying to use this program\n");
  142.         printf("Press any key to exit\n");
  143.         getch();
  144.         exit(1);
  145.     }
  146.     break;
  147. }
  148. }
  149.  
  150.  void create_account()  //function create account
  151.  {
  152.      char decision,new_choice;;
  153.      decision=='y';
  154.      int r;
  155.     srand((unsigned)time(0));//UNSIGNED PREVENTS RANDOM NEGATIVE NUMBERS FROM GENERATING
  156.     r=(rand()*999999999);//THE LARGER NUMBERS INCREASE A CHANCE OF GENERATING LARGER RANDOM NUMBERS WHICH IS MORE SUITABLE FOR A BANKING AGENCY
  157.     r=(rand()%9999999999999)+1;//IF THIS LINE IS ABSENT, THE NUMBERS WONT BE RANDOM ON EACH LOOP, ONLY AFTER THE PROGRAM CLOSES AND RE-OPENS
  158.     int current_year=2014;
  159.      do
  160. {
  161. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  162. printf("This is a list of our current savings plan system which you will choose from\n");
  163. printf("\n\t      ||                1. One year                    ||\n\t");
  164. printf("      ||                2. Two years                   ||\n\t");
  165. printf("      ||                3. Three years                 ||\n\t");
  166. printf("      ||                4. Four years                  ||\n\t");
  167. printf("      ||                5. Five years                  ||\n\n");
  168.  
  169. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  170. printf("Please note...you should enter the corresponding number for the desired savings plan\n");
  171. printf("You may now enter the savings plan desired\n");
  172. scanf("%s",&students.payment_type);
  173. switch(students.payment_type)
  174. {
  175. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  176. case '1':
  177.     printf("You have decided to use a savings plan of 1 year\n");
  178.     break;
  179.  
  180. case '2':
  181.  
  182.     printf("You have decided to use a savings plan of 2 years\n");
  183.     break;
  184.  
  185. case '3':
  186.  
  187.     printf("You have decided to use a savings plan of 3 years\n");
  188.     break;
  189.  
  190.  
  191. case '4':
  192.     printf("You have decided to use a savings plan of 4 years\n");
  193.     break;
  194.  
  195.  
  196. case '5':
  197.     printf("You have decided to use a savings plan of 5 years\n");
  198.     break;
  199.  
  200. default:
  201.     system("cls");
  202.     printf("Invalid option entered\n");
  203.     printf("Press any key to continue\n");
  204.     getch();
  205.     system("cls");
  206.     display_main_menu();
  207.     break;
  208. }
  209. printf("A minimum opening fee of $100 is required\n");
  210. printf("Enter the minimum opening fee\n");
  211. scanf("%f",&students.acc_fee);
  212. if(students.acc_fee<100)
  213. {
  214.     printf("The fee entered is too low\n");
  215.     printf("Press enter to return to the main menu\n");
  216.     getch();
  217.     display_main_menu();
  218. }
  219. else if(students.acc_fee<=100)
  220. {
  221.     printf("Your account balance is $%.2f.It will be saved in your creating account\n",students.acc_fee);
  222.     printf("Press enter to continue\n");
  223.     getch();
  224. }
  225. else if(students.acc_fee>100)
  226. {
  227.     students.acc_change=students.acc_fee-100;
  228.     printf("You have an existing change of $%.2f",students.acc_change);
  229.     printf("\nIf you wish to retrieve it, a withdrawal must be made after the account has been created\n");
  230.     printf("Press enter to continue\n");
  231.     getch();
  232. }
  233.  
  234. students.withdraw_change=students.acc_change;
  235. students.acc_bal=students.acc_fee;
  236. system("cls");
  237.  
  238.  
  239. printf("it is now time to create an account please enter the information required\n\n");
  240. printf("enter your firstname\n");
  241. scanf("%s",&students.firstname);
  242. printf("enter your lastname\n");
  243. scanf("%s",&students.lastname);
  244. printf("Enter the name of your parish\n");
  245. scanf("%s",&students.parish);
  246.  
  247. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  248. printf("\nTo sign up with us, ages must be 18 or older but less than 80 years of age\n");
  249. printf("You may now enter your year of birth\n");
  250. scanf("%d",&students.yob);
  251. students.age_calculation = current_year-students.yob;
  252. printf("Your age is %d ",students.age_calculation);
  253. if(students.age_calculation >= 18 && students.age_calculation<=80)
  254. {
  255.     printf("Which is an acceptable age\n");
  256.     printf("Please enter a password\n");
  257.     scanf("%s",&students.password);
  258.     system("cls");
  259.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  260.     printf("Please Hold, Creating Account...");
  261.     Sleep(3000);
  262.     system("cls");
  263.     printf("Accepting Data....");
  264.     Sleep(300);
  265.     system("cls");
  266.     printf("Enabling Data De-Fragmentation.....");
  267.     Sleep(300);
  268.     system("cls");
  269.     printf("Organizing File Memory...");
  270.     Sleep(300);
  271.     system("cls");
  272.     printf("Initiating Data Logs...");
  273.     Sleep(300);
  274.     system("cls");
  275.     printf("Data Checking...");
  276.     Sleep(300);
  277.     system("cls");
  278.     printf("Initializing Validity Check...");
  279.     Sleep(300);
  280.     system("cls");
  281.     printf("Locating Account Addresses..");
  282.     Sleep(300);
  283.     system("cls");
  284.     printf("Initiating Data Storage...");
  285.     Sleep(300);
  286.     system("cls");
  287.     printf("Finalizing DataBase Entry...");
  288.     Sleep(2000);
  289.     system("cls");
  290.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  291.     printf("Your account has been successfully created!\n");
  292.     printf("You have been assigned the account number : %d\n\n",r);
  293.     printf("Please keep your account number and password safe and confidential for they will be used later for deposits and withdrawals\n\n");
  294.     printf("Your information is as follows:\n");
  295.  
  296.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  297.     acc=fopen("Active Accounts.txt","a");//   FILE HOLDING THE SUCCESSFULLY CREATED ACCOUNTS
  298.     if (acc==NULL)
  299.     {
  300.     printf("Error opening file!\n");
  301.     exit(1);
  302.     }
  303.     fprintf(acc,">> Account #                  : %d\n",r);
  304.     fprintf(acc,">> First Name                 : %s\n",students.firstname);
  305.     fprintf(acc,">> Last Name                  : %s\n",students.lastname);
  306.     fprintf(acc,">> Parish                     : %s\n",students.parish);
  307.     fprintf(acc,">> Year of Birth              : %d\n",students.yob);
  308.     fprintf(acc,">> Age                        : %d\n",students.age_calculation);
  309.     fprintf(acc,">> Savings Period             : %d year(s)\n",students.payment_type);
  310.     fprintf(acc,">> Password                   : %s\n",students.password);
  311.     fprintf(acc,">> Change(left from fee paid) : $%.2f\n",students.withdraw_change);
  312.     fprintf(acc,">> Account balance            : $%.2f\n",students.acc_bal);
  313.     fprintf(acc,"======================================================\n");
  314.     fclose(acc);
  315.  
  316.     printf("================================================================================");
  317.     printf("                   >> Account #                  : %d\n",r);
  318.     printf("                   >> First Name                 : %s\n",students.firstname);
  319.     printf("                   >> Last Name                  : %s\n",students.lastname);
  320.     printf("                   >> Parish                     : %s\n",students.parish);
  321.     printf("                   >> Year of Birth              : %d\n",students.yob);
  322.     printf("                   >> Age                        : %d\n",students.age_calculation);
  323.     printf("                   >> Savings Period             : %d year(s)\n",students.payment_type);
  324.     printf("                   >> Password                   : %s\n",students.password);
  325.     printf("                   >> Change(left from fee paid) : $%.2f\n",students.withdraw_change);
  326.     printf("                   >> Account balance            : $%.2f\n",students.acc_bal);
  327.     printf("================================================================================\n");
  328.  
  329. }
  330. else if(students.age_calculation >=80)
  331. {
  332.        printf("Were very sorry but you are too old to create an account with us\n\n");
  333. }
  334.  
  335. else
  336.     {
  337.     printf("You are too young to create an account here sorry\n\n");
  338.     }
  339.     printf("If a mistake was made you can repeat the procedure of creating another savings\n");
  340.     printf("account\n\n");
  341.     printf("Do you wish to repeat? <y or n>\n\n");
  342.     scanf("%s",&decision);
  343.     system("cls");
  344.  
  345. }
  346. while(decision=='Y'||decision=='y');
  347. if(decision=='N'||decision=='n')
  348. {
  349.     printf("You are now a member of this banking agency! ....\n");
  350.        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
  351.     main_or_exit:
  352.     printf("\n\t      ||                A.<MAIN MENU>            ||\n\t");
  353.     printf("      ||                B.<EXIT>                 ||\n\n");
  354.     printf("Please select the desired option <a or b>\n\n");
  355.     scanf("%s",&new_choice);
  356.  
  357.     if(new_choice=='A'||new_choice=='a')
  358.       {
  359.          display_main_menu();
  360.       }
  361.  
  362.     else if(new_choice=='B'||new_choice=='b')
  363.     {
  364.         exit(1);
  365.     }
  366.     else
  367.     {
  368.         system("cls");
  369.         printf("Invalid option entered\n");
  370.         printf("Please read carefully and re-enter the option desired\n");
  371.         goto main_or_exit;
  372.     }
  373. }
  374.  }
  375.  
  376.  
  377.  void make_withdrawal()  //function make a withdrawal from an account
  378.  {
  379.     system("cls");
  380.     logo();
  381.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  382.     printf("\n\nWITHDRAWAL PROCESSING IS DONE HERE\n\n");
  383.     printf("Please enter your account number");
  384.     scanf("%d",&students.account_num);
  385.  }
  386.  
  387.  
  388.  void make_deposit()  //function make deposit to an account
  389.  {
  390.     system("cls");
  391.     logo();
  392.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  393.     printf("\n\nDEPOSIT PROCESSING IS DONE HERE\n\n");
  394.     printf("Please enter your account number");
  395.     scanf("%d",&students.account_num);
  396.     //fp=fopen("Active Accounts.txt","r");
  397.     //fseek(fp,0L,0);
  398.         /*if(account_num==r)
  399.         {
  400.         printf("Enter the amount of money to be deposited");
  401.         scanf("%f",&deposit);
  402.         acc_bal=acc_bal+deposit;
  403.         printf("%.2f",acc_bal);
  404.         }*/
  405.  }
  406.  
  407.  
  408.  void modify_account() //function modify an account
  409.  {
  410.      system("cls");
  411.      logo();
  412.      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  413.      int id;
  414.      printf("\n\nMODIFYING ACCOUNTS IS DONE HERE\n\n");
  415.      printf("Please enter your account number");
  416.      scanf("%d",&id);
  417.  }
  418.  
  419. void make_donation() //function make a donation to the bank
  420. {
  421.      system("cls");
  422.      logo();
  423.      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
  424.      int id;
  425.      printf("\n\nDONATION PROCESSING IS DONE HERE\n\n");
  426.      printf("Please enter your account number");
  427.      scanf("%d",&id);
  428.  
  429. }
  430.  
  431. void logo()
  432. {
  433.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  434.         printf("\t     ===================================================           \n\t");
  435.     printf("     @@@@@@@@@@      THE OLD HARBOUR    @@@@@@@@@@@@@@@@           \n\t");
  436.     printf("     @@@@@@@@@@    HIGH SCHOOL BANKING  @@@@@@@@@@@@@@@@           \n\t");
  437.     printf("     @@@@@@@@@@          SYSTEM         @@@@@@@@@@@@@@@@           \n\t");
  438.     printf("     ===================================================           \n\n");
  439.  
  440. }
Add Comment
Please, Sign In to add comment