You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.1 KiB

  1. #include "mainMenu.h"
  2. #include "employeeLogin.h"
  3. #include "createEmployeeAccount.h"
  4. #include "createCustomer.h"
  5. #include "error.h"
  6. #include "displayMenuCalculator.h"
  7. bool agePermission(int age)
  8. {
  9. return age >= 18;
  10. }
  11. bool checkIfInteger(char* userInput)
  12. {
  13. char *endPointer;
  14. /*the endPointer points to the first non-integer character signaled to stop conversion*/
  15. strtol(userInput, &endPointer, 10);
  16. return !(endPointer == userInput || *endPointer != '\0');
  17. }
  18. bool chooseOption(int choiceInput)
  19. {
  20. return !(choiceInput < 1 || choiceInput > 6);
  21. }
  22. void ageInput()
  23. {
  24. char* userInput = malloc(20*sizeof(char*));
  25. char* userInputPointer;
  26. int input, ctr=0;
  27. long age;
  28. printf("\nPlease specify your age : ");
  29. while((input=getchar())!='\n'){
  30. *(userInput+ctr) = input;
  31. ++ctr;
  32. }
  33. *(userInput+ctr) = '\0';
  34. while (true)
  35. {
  36. /*the userInput string is changed to a number with the strtol function*/
  37. age = strtol(userInput,&userInputPointer,10);
  38. if((checkIfInteger(userInput))&& (agePermission(age)))
  39. {
  40. printf("Access granted!\n\n\n\n");
  41. showMenu();
  42. menuInput();
  43. break;
  44. }
  45. else if((checkIfInteger(userInput)) && !(agePermission(age)))
  46. {
  47. errorMessage(-5);
  48. break;
  49. }
  50. else
  51. {
  52. printf("input invalid! try again!\n");
  53. scanf("%s",userInput);
  54. }
  55. }
  56. }
  57. void menuInput()
  58. {
  59. char choiceInput[20];
  60. char* choiceInputPointer;
  61. int selection, input, ctr = 0;
  62. while((input=getchar())!='\n'){
  63. choiceInput[ctr] = input;
  64. ++ctr;
  65. }
  66. choiceInput[ctr] = '\0';
  67. selection = strtol(choiceInput, &choiceInputPointer, 10);
  68. while (!checkIfInteger(choiceInput) || !chooseOption(selection))
  69. {
  70. printf("Input invalid! try again!\n");
  71. ctr = 0;
  72. while((input=getchar())!='\n'){
  73. choiceInput[ctr] = input;
  74. ++ctr;
  75. }
  76. choiceInput[ctr] = '\0';
  77. selection = strtol(choiceInput, &choiceInputPointer, 10);
  78. }
  79. switch(selection)
  80. {
  81. case 1 : collectCustomerDataForLogin(0);
  82. break;
  83. case 2 : collectCustomerProperties();
  84. break;
  85. case 3 : getEmployeeAccessCode();
  86. break;
  87. case 4 : getNewEmployeeCredentials();
  88. break;
  89. case 5 : displayMenuCalculator('c');
  90. break;
  91. case 6 : printf("\e[1;1H\e[2J");
  92. printf("\nsee you next time !\n\n");
  93. break;
  94. }
  95. }
  96. void showMenu()
  97. {
  98. printf("\t\t\t\t\t\t\t Welcome to Bank Manager!");
  99. printf("\n\n\n\n\t\t\t\t\t\tPlease select one of the following functions!");
  100. printf("\n\n\n\n\t\t\t\t\t\t ->Login as an existing costumer.");
  101. printf("\n\n\t\t\t\t\t\t ->Register as a new costumer.");
  102. printf("\n\n\t\t\t\t\t\t ->Login as an Employee.");
  103. printf("\n\n\t\t\t\t\t\t ->Register as an Employee.");
  104. printf("\n\n\t\t\t\t\t\t ->Calculator");
  105. printf("\n\n\t\t\t\t\t\t\t\t ->Exit.\n");
  106. printf("\n\n\n\n\n Selection :\n");
  107. }