HI there,
I implemented a menu with a switch statement with which one can navigate through the different options I offered, which coincide, in turn, with the cases on the switch statement.
I intended the line that contains 'default' for the menu to return to the initial state, that is where it asks me for the options I want to enter.
However instead of returning to the default state in which I can select the option that I want, the program terminates. Everything else works fine in the program... I thought about implementing a goto statement but this would be in violation of 'good programming practices' .... what can I do?
Also in order for the program to continue until the end of the process I removed the break; statements within the switch statement. Is this orthodox? I am thinking that perhaps I should have used if statements and do whiles... any suggestions?
Thank you
Code:int main(int argc, char** argv) { int option; menu(); printf("Enter option: "); // this is the state in which I want the program when finishing <<<HERE scanf("%d",&option); switch (option) { case 1:printf("Create employee\n"); fill_staff(); // takes index from user employee_create(); // fills an array with index above case 2: printf("Enter employee data\n"); for (d = 1; d <= emp_num; d++) employee_data(); //enter data for the employees created case 3:printf("Print employee list\n"); for (d = 1; d <= emp_num; d++) print_employee(); //prints the array of employees default: printf("\n\n\nEnter option: "); //Return back to the original state and continue choosing options -- THIS IS WHERE THE PROBLEM IS <<< scanf("%d",&option); } return (EXIT_SUCCESS); }



LinkBack URL
About LinkBacks



