From 7b176305a3fa3cfde26f0efe2c03aec94da68be2 Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Sat, 28 Jan 2023 15:29:19 +0100 Subject: [PATCH 1/7] Initial commit --- .gitignore | 1 + build-project.sh | 5 +++++ src/main.c | 6 ++++++ team.md | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 .gitignore create mode 100644 build-project.sh create mode 100644 src/main.c create mode 100644 team.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/build-project.sh b/build-project.sh new file mode 100644 index 0000000..c75f560 --- /dev/null +++ b/build-project.sh @@ -0,0 +1,5 @@ +clear +cd src/ +gcc main.c +./a.out +rm a.out \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..a6b9b24 --- /dev/null +++ b/src/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + + return 0; +} \ No newline at end of file diff --git a/team.md b/team.md new file mode 100644 index 0000000..f0e0a28 --- /dev/null +++ b/team.md @@ -0,0 +1,6 @@ +- Can Hacioglu, fdlt3817 +- Atharva Kishor Naik, fdai7514 +- Julius Philipp Engel, fdai7057 +- Shivam Chaudhary, fdlt3781 +- Mohamed Yahya Dahi, fdai6618 +- Haytham Daoula, fdai7207 \ No newline at end of file From c135603ed0fd1ccdba844b698ec7a3999221769b Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sat, 28 Jan 2023 21:38:46 +0100 Subject: [PATCH 2/7] implement unit tests for the functions agePermission() and checkIfInteger() --- build-project.sh | 5 +- project.yml | 101 +++++++++++++++++++++++++++++ src/main.c | 2 +- src/mainMenu.c | 42 +++++++++++++ src/mainMenu.h | 13 ++++ test/support/.gitkeep | 0 test/test_mainMenu.c | 143 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 303 insertions(+), 3 deletions(-) mode change 100644 => 100755 build-project.sh create mode 100644 project.yml create mode 100644 src/mainMenu.c create mode 100644 src/mainMenu.h create mode 100644 test/support/.gitkeep create mode 100644 test/test_mainMenu.c diff --git a/build-project.sh b/build-project.sh old mode 100644 new mode 100755 index c75f560..4247c59 --- a/build-project.sh +++ b/build-project.sh @@ -1,5 +1,6 @@ clear +ceedling test:all cd src/ -gcc main.c +gcc main.c mainMenu.c ./a.out -rm a.out \ No newline at end of file +rm a.out diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..e253248 --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:test/** + - -:test/support + :source: + - src/** + :support: + - test/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/main.c b/src/main.c index a6b9b24..3f845e6 100644 --- a/src/main.c +++ b/src/main.c @@ -3,4 +3,4 @@ int main() { return 0; -} \ No newline at end of file +} diff --git a/src/mainMenu.c b/src/mainMenu.c new file mode 100644 index 0000000..54d20ad --- /dev/null +++ b/src/mainMenu.c @@ -0,0 +1,42 @@ +#include"mainMenu.h" + + +bool agePermission(int age){ + + if(age >= 18) + { + + return true; + + } + + else + { + + return false; + + } + +} + +bool checkIfInteger(char* input){ + + char *end_pointer; + + strtol(input, &end_pointer, 10); + + if (end_pointer == input || *end_pointer != '\0') + { + + return false; + + } + + else + { + + return true; + + } +} + diff --git a/src/mainMenu.h b/src/mainMenu.h new file mode 100644 index 0000000..61192be --- /dev/null +++ b/src/mainMenu.h @@ -0,0 +1,13 @@ +#ifndef MAINMENU_H_ +#define MAINMENU_H_ + +#include +#include +#include +#include + +bool agePermission(int age); +bool checkIfInteger(char* userInput); + +#endif + diff --git a/test/support/.gitkeep b/test/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c new file mode 100644 index 0000000..515237d --- /dev/null +++ b/test/test_mainMenu.c @@ -0,0 +1,143 @@ +#ifdef TEST + +#include "unity.h" + +#include "mainMenu.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} +void test_agePermissionValidAge(void) +{ + //Test case : 0 + + //Arrange + + int validAge[83]; + + bool validAgeResult[83]; + + int j=0; + + for(int i =18;i<101;i++){ + + validAge[j]= i; + j++; + } + + //Act + + for(int i=0;i<83;i++){ + + validAgeResult[i] = agePermission(validAge[i]); + } + + //Assert + + for(int i=0;i<83;i++){ + + TEST_ASSERT_TRUE(validAgeResult[i]); + + } + +} + +void test_agePermissionInvalidAge(void) +{ + + //Test case : 1 + + //Arrange + + int invalidAge[117]; + + bool invalidAgeResult[117]; + + int j=0; + + for(int i =-100;i<18;i++){ + + invalidAge[j]= i; + j++; + } + + //Act + + for(int i=0;i<117;i++){ + + invalidAgeResult[i] = agePermission(invalidAge[i]); + + } + + //Assert + + for(int i=0;i<117;i++){ + + TEST_ASSERT_FALSE(invalidAgeResult[i]); + + } + +} + +void test_IsInteger(void) +{ + + //Arrange + + char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; + + bool inputIsIntegerResult[19]; + + //Act + + for(int i=0;i<19;i++) + { + + inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); + + } + + //Assert + + for(int i=0;i<19;i++) + { + + TEST_ASSERT_TRUE(inputIsIntegerResult[i]); + + } + +} + +void test_IsNotInteger(void) +{ + + //Arrange + + char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" }; + + bool inputIsNotIntegerResult[19]; + + //Act + + for(int i=0;i<19;i++) + { + + inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); + + } + + //Assert + + for(int i=0;i<19;i++) + { + + TEST_ASSERT_FALSE(inputIsNotIntegerResult[i]); + + } + +} +#endif // TEST From dcee631e6b743f9d08c96bf0945cc97291f714ff Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 29 Jan 2023 00:00:06 +0100 Subject: [PATCH 3/7] implement the functions ageInput() and showMenu() to execute mainMenu.c . --- build-project.sh | 6 ++--- src/main.c | 4 +++- src/mainMenu.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ src/mainMenu.h | 3 +++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/build-project.sh b/build-project.sh index 4247c59..ea712c3 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,6 +1,6 @@ clear ceedling test:all cd src/ -gcc main.c mainMenu.c -./a.out -rm a.out +gcc -o main main.c mainMenu.c +./main +rm main diff --git a/src/main.c b/src/main.c index 3f845e6..b37734e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,8 @@ -#include +#include "mainMenu.h" int main() { + + ageInput(); return 0; } diff --git a/src/mainMenu.c b/src/mainMenu.c index 54d20ad..9cd19c0 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -39,4 +39,63 @@ bool checkIfInteger(char* input){ } } +void ageInput(){ + char input[20]; + char* input_pointer; + + long age; + + printf("\nPlease specify your age : "); + scanf("%s",input); + + + while (true) + { + age = strtol(input,&input_pointer,10); + + if(checkIfInteger(input) == true && agePermission(age)== true) + { + age = strtol(input,&input_pointer,10); + + printf("Access granted!\n\n\n\n"); + + showMenu(); + + break; + + } + + else if(checkIfInteger(input) == true && agePermission(age)== false) + { + + printf("You should be at least 18 years old to create a bank account!\n"); + + break; + + } + + else + { + printf("input invalid! try again!\n"); + + scanf("%s",input); + + } + + } + +} + + +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\t\t ->Exit.\n"); + printf("\n\n\n\n\n Selection :\n"); + +} diff --git a/src/mainMenu.h b/src/mainMenu.h index 61192be..ccc7d9c 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -9,5 +9,8 @@ bool agePermission(int age); bool checkIfInteger(char* userInput); +void ageInput(); +void showMenu(); + #endif From cf756de8b96281c35aa2efb3dd8912357c69c3b2 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 29 Jan 2023 00:25:24 +0100 Subject: [PATCH 4/7] refactoring: changed some variable names, made code more readable and enhanced some functions --- src/mainMenu.c | 59 ++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/mainMenu.c b/src/mainMenu.c index 9cd19c0..dd249fc 100644 --- a/src/mainMenu.c +++ b/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){ - - char *end_pointer; - - strtol(input, &end_pointer, 10); - - if (end_pointer == input || *end_pointer != '\0') - { +bool checkIfInteger(char* userInput) +{ - return false; + char *endPointer; - } + /*the endPointer points to the first non-integer character signaled to stop conversion*/ - else - { + strtol(userInput, &endPointer, 10); - return true; + return !(endPointer == userInput || *endPointer != '\0'); - } } -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!"); From 8543ec2ec2705a60a59b5e5b92891ce30602985f Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Sun, 29 Jan 2023 01:08:46 +0100 Subject: [PATCH 5/7] refactoring: removed redundant code in the unit tests to improve readability and maintainability. --- test/test_mainMenu.c | 142 +++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 78 deletions(-) diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c index 515237d..eb93bb7 100644 --- a/test/test_mainMenu.c +++ b/test/test_mainMenu.c @@ -6,138 +6,124 @@ void setUp(void) { + } void tearDown(void) { + } + void test_agePermissionValidAge(void) { //Test case : 0 - //Arrange - - int validAge[83]; - - bool validAgeResult[83]; + /*Arrange*/ - int j=0; + int Age = 18; - for(int i =18;i<101;i++){ + bool validAgeResult[83]; - validAge[j]= i; - j++; - } - - //Act + /*Act*/ - for(int i=0;i<83;i++){ - - validAgeResult[i] = agePermission(validAge[i]); + for(int i =0;i<83;i++){ + + validAgeResult[i]= Age + i; } - - //Assert + + + /*Assert*/ for(int i=0;i<83;i++){ - - TEST_ASSERT_TRUE(validAgeResult[i]); - - } + TEST_ASSERT_TRUE(validAgeResult[i]); + + } + } void test_agePermissionInvalidAge(void) { //Test case : 1 - - //Arrange - + + /*Arrange*/ + int invalidAge[117]; - + bool invalidAgeResult[117]; - - int j=0; - - for(int i =-100;i<18;i++){ - - invalidAge[j]= i; - j++; + + + for(int i =-100;i<18;i++) + { + + invalidAge[i+100]= i; } - - //Act - - for(int i=0;i<117;i++){ - + + /*Act*/ + + for(int i=0;i<117;i++) + { + invalidAgeResult[i] = agePermission(invalidAge[i]); } - - //Assert - - for(int i=0;i<117;i++){ - + + /*Assert*/ + + for(int i=0;i<117;i++) + { + TEST_ASSERT_FALSE(invalidAgeResult[i]); - - } + + } } void test_IsInteger(void) { - - //Arrange - - char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; - bool inputIsIntegerResult[19]; + //test case 0 - //Act - - for(int i=0;i<19;i++) - { + /*Arrange*/ - inputIsIntegerResult[i] = checkIfInteger(inputIsInteger[i]); - - } + char* inputIsInteger[] = {"-10000000","-2000000","-354698","-66667","-7878","-987","-64","-5","0","1","2","10","201","333","4321","56974","698751","7878989","88954621" }; + + bool inputIsIntegerExpected = true; - //Assert + /*Act and Assert*/ for(int i=0;i<19;i++) { + bool inputIsIntegerResult = checkIfInteger(inputIsInteger[i]); - TEST_ASSERT_TRUE(inputIsIntegerResult[i]); + TEST_ASSERT_EQUAL(inputIsIntegerExpected,inputIsIntegerResult); - } + } } void test_IsNotInteger(void) { + //test case 1 + + /*Arrange*/ - //Arrange - char* inputIsNotInteger[] = {"0.15","3.141592653589793238","5.3254f","-6.264","-7878.3261","foo","Bar","FIZZ","buzZ","joHN","jAnE","foo-bar","3,15","2k13",""," ","-","+","/*-+.,/=" }; - - bool inputIsNotIntegerResult[19]; - - //Act - - for(int i=0;i<19;i++) - { - - inputIsNotIntegerResult[i] = checkIfInteger(inputIsNotInteger[i]); - - } - - //Assert - + + bool inputIsNotIntegerExpected = false; + + /*Act and Assert*/ + + for(int i=0;i<19;i++) { - - TEST_ASSERT_FALSE(inputIsNotIntegerResult[i]); - + bool inputIsNotIntegerResult = checkIfInteger(inputIsNotInteger[i]); + + TEST_ASSERT_EQUAL(inputIsNotIntegerExpected,inputIsNotIntegerResult); + } + } #endif // TEST From ceccdd60a9c47576822201d15f245325391a29f0 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 30 Jan 2023 15:13:57 +0100 Subject: [PATCH 6/7] implement unit tests for the function chooseOption(). --- .gitignore | 3 +- src/mainMenu.c | 20 +++++++- src/mainMenu.h | 1 + test/test_mainMenu.c | 111 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 126 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 496ee2c..dce188f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +.swp diff --git a/src/mainMenu.c b/src/mainMenu.c index dd249fc..eca4c34 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,4 +1,4 @@ -#include"mainMenu.h" +#include "mainMenu.h" bool agePermission(int age) @@ -20,6 +20,22 @@ bool checkIfInteger(char* userInput) return !(endPointer == userInput || *endPointer != '\0'); } + +bool chooseOption(int choiceInput) +{ + + if(choiceInput < 1 || choiceInput > 4) + { + return false; + } + + else + { + return true; + } + +} + void ageInput() { @@ -82,3 +98,5 @@ void showMenu() printf("\n\n\n\n\n Selection :\n"); } + + diff --git a/src/mainMenu.h b/src/mainMenu.h index ccc7d9c..6974d21 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -8,6 +8,7 @@ bool agePermission(int age); bool checkIfInteger(char* userInput); +bool chooseOption(int choiceInput); void ageInput(); void showMenu(); diff --git a/test/test_mainMenu.c b/test/test_mainMenu.c index eb93bb7..ea65cc2 100644 --- a/test/test_mainMenu.c +++ b/test/test_mainMenu.c @@ -26,7 +26,7 @@ void test_agePermissionValidAge(void) /*Act*/ - for(int i =0;i<83;i++){ + for(int i =0; i < 83; i++){ validAgeResult[i]= Age + i; } @@ -34,7 +34,7 @@ void test_agePermissionValidAge(void) /*Assert*/ - for(int i=0;i<83;i++){ + for(int i=0; i < 83; i++){ TEST_ASSERT_TRUE(validAgeResult[i]); @@ -54,7 +54,7 @@ void test_agePermissionInvalidAge(void) bool invalidAgeResult[117]; - for(int i =-100;i<18;i++) + for(int i =-100; i < 18; i++) { invalidAge[i+100]= i; @@ -62,7 +62,7 @@ void test_agePermissionInvalidAge(void) /*Act*/ - for(int i=0;i<117;i++) + for(int i=0; i < 117; i++) { invalidAgeResult[i] = agePermission(invalidAge[i]); @@ -71,7 +71,7 @@ void test_agePermissionInvalidAge(void) /*Assert*/ - for(int i=0;i<117;i++) + for(int i=0; i < 117; i++) { TEST_ASSERT_FALSE(invalidAgeResult[i]); @@ -93,7 +93,7 @@ void test_IsInteger(void) /*Act and Assert*/ - for(int i=0;i<19;i++) + for(int i=0; i < 19; i++) { bool inputIsIntegerResult = checkIfInteger(inputIsInteger[i]); @@ -116,7 +116,7 @@ void test_IsNotInteger(void) /*Act and Assert*/ - for(int i=0;i<19;i++) + for(int i=0; i<19; i++) { bool inputIsNotIntegerResult = checkIfInteger(inputIsNotInteger[i]); @@ -126,4 +126,101 @@ void test_IsNotInteger(void) } +void test_validChoiceInput(void) +{ + //test case 0 + + /*Arrange*/ + + int validInput[4]; + + bool validInputResult[4]; + + /*Act*/ + + for(int i = 0; i < 4; i++) + { + validInput[i] = i + 1; + } + + for(int i = 0; i < 4; i++) + { + validInputResult[i] = chooseOption(validInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 4; i++) + { + TEST_ASSERT_TRUE(validInputResult[i]); + } + +} + +void test_invalidChoiceInput_firstCase(void) +{ + // test case 1 + + /*Arrange*/ + + int invalidInput[100]; + + bool invalidInputResult[100]; + + /*Act*/ + + for(int i = -100; i < 0; i++) + { + invalidInput[i+100] = i; + } + + for(int i = 0; i < 100; i++) + { + invalidInputResult[i] = chooseOption(invalidInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 100; i++) + { + TEST_ASSERT_FALSE(invalidInputResult[i]); + } + +} + +void test_invalidChoiceInput_secondCase(void) +{ + // test case 2 + + /*Arrange*/ + + int invalidInput[100]; + + bool invalidInputResult[100]; + + /*Act*/ + + for(int i = 0; i < 100; i++) + { + invalidInput[i] = i + 5; + } + + for(int i = 0; i < 100; i++) + { + invalidInputResult[i] = chooseOption(invalidInput[i]); + } + + /*Assert*/ + + for(int i = 0; i < 100; i++) + { + TEST_ASSERT_FALSE(invalidInputResult[i]); + } + +} + + + + + #endif // TEST From 26ea996b0b78ca83e38dcce7bb8bc3bab6898544 Mon Sep 17 00:00:00 2001 From: fdai7207 Date: Mon, 30 Jan 2023 16:26:43 +0100 Subject: [PATCH 7/7] implement the function menuInput(), in order for the user to choose a menu option. --- src/mainMenu.c | 64 +++++++++++++++++++++++++++++++++++++++++++++----- src/mainMenu.h | 1 + 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/mainMenu.c b/src/mainMenu.c index eca4c34..bed41d9 100644 --- a/src/mainMenu.c +++ b/src/mainMenu.c @@ -1,4 +1,4 @@ -#include "mainMenu.h" +#include"mainMenu.h" bool agePermission(int age) @@ -24,14 +24,15 @@ bool checkIfInteger(char* userInput) bool chooseOption(int choiceInput) { - if(choiceInput < 1 || choiceInput > 4) + if(choiceInput<1 || choiceInput>4) { - return false; + return false; } else { - return true; + + return true; } } @@ -54,11 +55,12 @@ void ageInput() if((checkIfInteger(userInput))&& (agePermission(age))) { - //age = strtol(userInput,&userInputPointer,10); printf("Access granted!\n\n\n\n"); showMenu(); + + menuInput(); break; @@ -85,6 +87,57 @@ void ageInput() } +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) + { + + 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 showMenu() { @@ -99,4 +152,3 @@ void showMenu() } - diff --git a/src/mainMenu.h b/src/mainMenu.h index 6974d21..1be573f 100644 --- a/src/mainMenu.h +++ b/src/mainMenu.h @@ -11,6 +11,7 @@ bool checkIfInteger(char* userInput); bool chooseOption(int choiceInput); void ageInput(); +void menuInput(); void showMenu(); #endif