0

So as you can see in the code, it is just a bunch of menus, I'm working on a university project, and the problem is, the do/while loop is working as intended in the main_menu(); fucntion, it is not however in the admin_menu(); when the user is on the main menu he is being forced, as intended to either input a valid number or exit with 0, it should work the same on the admin menu but it doesn't matter the number I input the program just ends.

void main_menu(){

    int option;
    
    do{
        
        printf("\n1: Registar Utente");
        printf("\n2: Registar Doctor");
        printf("\n3: Login Utente");
        printf("\n4: Login Doctor");
        printf("\n0: Sair \n");
        
        scanf("%d", &option);       
        
        switch(option){
        
            case 1: printf("Working\n");/*funtion to register a patient*/break;
            case 2: printf("Working\n");/*funtion to register a doctor */break;
            case 3: printf("Working\n");/*funtion to login a patient   */break;
            case 4: printf("Working\n");/*funtion to login a doctor    */break;
            case 99: admin_menu();      /*99 for admin access*/          break;
            
        }
        
        if (option != 1 || option != 2 || option != 3 || option != 4 || option != 99) printf("Insira uma opcao valida!!! \n");
    
    }while(option != 0);
    
    system("cls");
}


void patient_menu(){
    
    int option;
    
    do{
        printf("/n 1: Marcar uma consulta");
        printf("/n 2: Alterar informacoes");
        printf("/n 3: Apagar conta");
        printf("/m 0: Sair");
        
        scanf("%d",option);
        
        switch(option){
        
            case 1: printf("Working\n");/*funtion to unqueue        */break;
            case 2: printf("Working\n");/*funtion to edit user      */break;
            case 3: printf("Working\n");/*funtion to remove user    */break;
            
        }
        
        if (option != 0 || option != 1 || option != 2 || option != 3) printf("Insira uma opcao valida");
        
    }while(option != 0);
    
    system("cls");
}


void doctor_menu(){
    
    int option;
    
    do{
        printf("/n 1: Verificar lista de utentes");
        printf("/n 2: Alterar informacoes");
        printf("/n 3: Apagar conta");
        printf("/m 0: Sair");
        
        scanf("%d",option);
        
        switch(option){
        
            case 1: printf("Working\n");/*funtion to print queue    */break;
            case 2: printf("Working\n");/*funtion to edit user      */break;
            case 3: printf("Working\n");/*funtion to remove user    */break;
            
        }
        
        
        if (option != 0 || option != 1 || option != 2 || option != 3) printf("Insira uma opcao valida");
        
    }while(option != 0);
    
    system("cls");
}


void admin_menu(){

    int option;
    
    do{
        
        printf("\n1: Verificar lista de utentes");
        printf("\n2: Alterar informacoes utentes");
        printf("\n3: Alterar informacoes medicos");
        printf("\n4: Remover utente");
        printf("\n5: Remover medico");
        printf("\n0: Sair\n");
        
        scanf("%d", &option);       
        
        switch(option){
        
            case 1: printf("Working\n");/*funtion to print queue      */break;
            case 2: printf("Working\n");/*funtion to edit a patient   */break;
            case 3: printf("Working\n");/*funtion to edit a doctor    */break;
            case 4: printf("Working\n");/*funtion to remove a patient */break;
            case 5: printf("Working\n");/*funtion to remove a doctor  */break;
            
        }
        
        if (option != 1 || option != 2 || option != 3 || option != 4 || option != 5) printf("Insira uma opcao valida!!! \n");
    
    }while(option != 0);
    
    system("cls");
}


int main() {
    
    main_menu();
    
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
Matias04_
  • 11
  • 1
  • All the `||` should be `&&`. Or you could just use a `default:` case in the `switch` to handle when they give a wrong number. – Barmar May 11 '23 at 19:44
  • what is /n and /m in patient_menu and doctor_menu? – Erik May 12 '23 at 07:36
  • You should move the printf statements to outside the do while loop. And the code never calls any of the other menus except the admin_menu on 99. – Erik May 12 '23 at 07:38

0 Answers0