Print all results of a vector with a certain value

1

I'm starting the studies in C. I have a question about how to go through a vector looking for a value in it and print showing with printf all the values found.

The program I'm doing: link

In the above program, it would be case 5, where I want to show all employees by the job code. Thank you in advance

    
asked by anonymous 30.11.2016 / 12:18

1 answer

0

I could follow this logic:

case 5:
     //MOSTRA POR CARGO
     printf("Digite o codigo do cargo:\n");
     printf("\n 100\tEngenheiro\n 200\tMestre de Obras\n0\tPedreiro\n 400\tEstagiario\n");

     scanf("%i", &pesquisa);
     ok = 0;
     // Avisa se o cargo pesquisado nao existe
     if ((pesquisa != 100) && (pesquisa != 200) && (pesquisa != 300) (pesquisa != 400)){
        printf("Pesquisa invalida!");
     }
     else {
        // Loop para percorrer o vetor cargo e verificar a pesquisa
        for(j = 0; j < c; j++) {
           if(pesquisa==cargo[j]) {
              ok = 1;
              printf("\n***********************************\n");
              printf("Funcionario numero %i\n", j);
              printf("Matricula %i\n", matricula[j]);
              printf("Cargo:%i\n", cargo[j]);
              printf("Salario: $ %.2f\n", saldo[j]);
           }
        }
     }

     // Se nao encontrar nenhum funcionario pela pesquisa
     if (ok == 0){
        printf("Sem resultado!\n");
     }
break;
    
30.11.2016 / 12:57