Jump to content

Ver se o Codigo ja Existe


iCl4w
 Share

Recommended Posts

Estou a trabalhar em um projeto com estruturas e ele pede o cadastro de alunos, como faço pra "ver" se o código já foi cadastrado? Esse modo aí não está dando certo!

O programa não sai do canto! Alguém aí tem alguma sugestão? Usei o If.. Mas parece que não é a melhor saída!

int i, j;
    char cod[20];

    system("cls");
    for(i=0; i<10; i++)
    {
        VOLTAR_CODIGO:
        cout<<"Digite Codigo: ";

            gets(cod);
            if ((strcmp(total_alunos[i].cod_aluno,cod))==0) goto VOLTAR_CODIGO;
            
        gets(total_alunos[i].cod_aluno);
        cout<<"Digite o Nome: ";
        gets(total_alunos[i].nome_aluno);

        VOLTAR_SERIE:
        cout<<"Digite a Serie: ";

            cin>>j;
            if (j<5 || j>) goto VOLTAR_SERIE;

        cin>>total_alunos[i].serie;
    }

Aguardo respostas...

Link to comment
Share on other sites

Usando o do-while também não deu!

void cad_disciplina()
{
    int i, verigual;
    char codigodisc[50];

    system("cls");
    for(i=0; i<6; i++)
    {
        do {
            cout<<"Digite o Codigo: ";
            gets(codigodisc);
            verigual=(strcmp(total_disc[i].dcod_disc,codigodisc));
        }while(verigual!=0);

        strcpy(total_disc[i].dcod_disc,codigodisc);
        cout<<"Digite a Disciplina: ";
        gets(total_disc[i].descr);
        fflush(stdin);
        cout<<"Digite a Carga Horaria: ";
        cin>>total_disc[i].carga_hor;
        fflush(stdin);
    }
    getche();
    main();
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.