Browse Source

refactoring: changed some variable names, made code more readable and enhanced some functions

remotes/origin/feature/the-main-menu
fdai7207 2 years ago
parent
commit
cf756de8b9
  1. 59
      src/mainMenu.c

59
src/mainMenu.c

@ -1,62 +1,44 @@
#include"mainMenu.h"
bool agePermission(int age){
bool agePermission(int age)
{
if(age >= 18)
{
return true;
}
else
{
return false;
}
return age >= 18;
}
bool checkIfInteger(char* input){
bool checkIfInteger(char* userInput)
{
char *end_pointer;
char *endPointer;
strtol(input, &end_pointer, 10);
/*the endPointer points to the first non-integer character signaled to stop conversion*/
if (end_pointer == input || *end_pointer != '\0')
{
strtol(userInput, &endPointer, 10);
return false;
return !(endPointer == userInput || *endPointer != '\0');
}
else
{
return true;
}
}
void ageInput(){
void ageInput()
{
char input[20];
char* input_pointer;
char* userInput = malloc(20*sizeof(char*));
char* userInputPointer;
long age;
printf("\nPlease specify your age : ");
scanf("%s",input);
scanf("%s",userInput);
while (true)
{
age = strtol(input,&input_pointer,10);
age = strtol(userInput,&userInputPointer,10);
if(checkIfInteger(input) == true && agePermission(age)== true)
if((checkIfInteger(userInput))&& (agePermission(age)))
{
age = strtol(input,&input_pointer,10);
//age = strtol(userInput,&userInputPointer,10);
printf("Access granted!\n\n\n\n");
@ -66,7 +48,7 @@ void ageInput(){
}
else if(checkIfInteger(input) == true && agePermission(age)== false)
else if((checkIfInteger(userInput)) && !(agePermission(age)))
{
printf("You should be at least 18 years old to create a bank account!\n");
@ -79,7 +61,7 @@ void ageInput(){
{
printf("input invalid! try again!\n");
scanf("%s",input);
scanf("%s",userInput);
}
@ -88,7 +70,8 @@ void ageInput(){
}
void showMenu(){
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!");

Loading…
Cancel
Save