Browse Source

refactoring: made code more readable and enhanced the menuInput() and chooseOption() functions.

remotes/origin/beta
fdai7207 2 years ago
parent
commit
4d0091a099
  1. 2
      src/CustomerData.txt
  2. 157
      src/mainMenu.c

2
src/CustomerData.txt

@ -4,5 +4,3 @@ forename=Max
Surname=Mustermann
password=example
balance=0

157
src/mainMenu.c

@ -25,16 +25,7 @@ bool checkIfInteger(char* userInput)
bool chooseOption(int choiceInput)
{
if(choiceInput<1 || choiceInput>4)
{
return false;
}
else
{
return true;
}
return !(choiceInput < 1 || choiceInput > 4);
}
@ -55,148 +46,82 @@ void ageInput()
while (true)
{
age = strtol(userInput,&userInputPointer,10);
if((checkIfInteger(userInput))&& (agePermission(age)))
{
/*the userInput string is changed to a number with the strtol function*/
printf("Access granted!\n\n\n\n");
age = strtol(userInput,&userInputPointer,10);
showMenu();
menuInput();
if((checkIfInteger(userInput))&& (agePermission(age)))
{
printf("Access granted!\n\n\n\n");
showMenu();
menuInput();
break;
}
break;
}
else if((checkIfInteger(userInput)) && !(agePermission(age)))
{
else if((checkIfInteger(userInput)) && !(agePermission(age)))
{
printf("You should be at least 18 years old to create a bank account!\n");
break;
break;
}
else
{
printf("input invalid! try again!\n");
scanf("%s",userInput);
}
}
}
void menuInput()
{
char choiceInput[20];
char* choiceInputPointer;
int selection;
}
scanf("%s",choiceInput);
while(true)
{
selection = strtol(choiceInput,&choiceInputPointer,10);
if(chooseOption(selection) == true && checkIfInteger(choiceInput) == true)
{
switch(selection)
else
{
printf("input invalid! try again!\n");
scanf("%s",userInput);
int c;
/*this loop flushes the input buffer for the upcoming getchar*/
while ((c = getchar()) != '\n' && c != EOF) {};
case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n");
break;
case 2 : printf("\ncreateCostumerAccount() function will be implemented here soon\n\n");
break;
case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n");
}
break;
case 4 : printf("\e[1;1H\e[2J");
printf("\nsee you next time !\n\n");
break;
}
break;
}
else
{
printf("Input invalid! try again!\n");
scanf("%s",choiceInput);
}
}
}
void menuInput()
{
char choiceInput[20];
char* choiceInputPointer;
int selection;
int c;
scanf("%s",choiceInput);
scanf("%s", choiceInput);
int c;
/*this loop flushes the input buffer for the upcoming getchar*/
while ((c = getchar()) != '\n' && c != EOF) {};
selection = strtol(choiceInput, &choiceInputPointer, 10);
while(true)
while (!checkIfInteger(choiceInput) || !chooseOption(selection))
{
selection = strtol(choiceInput,&choiceInputPointer,10);
if(chooseOption(selection) == true && checkIfInteger(choiceInput) == true)
{
switch(selection)
{
case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n");
break;
printf("Input invalid! try again!\n");
case 2 : collectCustomerProperties();
break;
scanf("%s", choiceInput);
while ((c = getchar()) != '\n' && c != EOF) {};
case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n");
break;
case 4 : printf("\e[1;1H\e[2J");
printf("\nsee you next time !\n\n");
selection = strtol(choiceInput, &choiceInputPointer, 10);
}
break;
switch(selection)
{
case 1 : printf("\nLoginAsCostumer() function will be implemented here soon\n\n");
break;
}
break;
}
case 2 : collectCustomerProperties();
break;
else
{
printf("Input invalid! try again!\n");
case 3 : printf("\nLoginAsEmployee() function will be implemented here soon\n\n");
break;
scanf("%s",choiceInput);
}
case 4 : printf("\e[1;1H\e[2J");
printf("\nsee you next time !\n\n");
break;
}
}
void showMenu()
{

Loading…
Cancel
Save