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

#include "mainMenu.h"
#include "employeeLogin.h"
#include "createEmployeeAccount.h"
#include "createCustomer.h"
#include "error.h"
#include "displayMenuCalculator.h"
bool agePermission(int age)
{
return age >= 18;
}
bool checkIfInteger(char* userInput)
{
char *endPointer;
/*the endPointer points to the first non-integer character signaled to stop conversion*/
strtol(userInput, &endPointer, 10);
return !(endPointer == userInput || *endPointer != '\0');
}
bool chooseOption(int choiceInput)
{
return !(choiceInput < 1 || choiceInput > 6);
}
void ageInput()
{
char* userInput = malloc(20*sizeof(char*));
char* userInputPointer;
int input, ctr=0;
long age;
printf("\nPlease specify your age : ");
while((input=getchar())!='\n'){
*(userInput+ctr) = input;
++ctr;
}
*(userInput+ctr) = '\0';
while (true)
{
/*the userInput string is changed to a number with the strtol function*/
age = strtol(userInput,&userInputPointer,10);
if((checkIfInteger(userInput))&& (agePermission(age)))
{
printf("Access granted!\n\n\n\n");
showMenu();
menuInput();
break;
}
else if((checkIfInteger(userInput)) && !(agePermission(age)))
{
errorMessage(-5);
break;
}
else
{
printf("input invalid! try again!\n");
scanf("%s",userInput);
}
}
}
void menuInput()
{
char choiceInput[20];
char* choiceInputPointer;
int selection, input, ctr = 0;
while((input=getchar())!='\n'){
choiceInput[ctr] = input;
++ctr;
}
choiceInput[ctr] = '\0';
selection = strtol(choiceInput, &choiceInputPointer, 10);
while (!checkIfInteger(choiceInput) || !chooseOption(selection))
{
printf("Input invalid! try again!\n");
ctr = 0;
while((input=getchar())!='\n'){
choiceInput[ctr] = input;
++ctr;
}
choiceInput[ctr] = '\0';
selection = strtol(choiceInput, &choiceInputPointer, 10);
}
switch(selection)
{
case 1 : collectCustomerDataForLogin(0);
break;
case 2 : collectCustomerProperties();
break;
case 3 : getEmployeeAccessCode();
break;
case 4 : getNewEmployeeCredentials();
break;
case 5 : displayMenuCalculator('c');
break;
case 6 : printf("\e[1;1H\e[2J");
printf("\nsee you next time !\n\n");
break;
}
}
void showMenu()
{
printf("\t\t\t\t\t\t\t Welcome to Bank Manager!");
printf("\n\n\n\n\t\t\t\t\t\tPlease select one of the following functions!");
printf("\n\n\n\n\t\t\t\t\t\t ->Login as an existing costumer.");
printf("\n\n\t\t\t\t\t\t ->Register as a new costumer.");
printf("\n\n\t\t\t\t\t\t ->Login as an Employee.");
printf("\n\n\t\t\t\t\t\t ->Register as an Employee.");
printf("\n\n\t\t\t\t\t\t ->Calculator");
printf("\n\n\t\t\t\t\t\t\t\t ->Exit.\n");
printf("\n\n\n\n\n Selection :\n");
}