Code in the c++ dev of the problem, but in another compiler it works

Asked

Viewed 318 times

0

The code is stopping responding at the last execution.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, 
system("pause") or input loop */

typedef struct Aluno {
    int ra;
    float nota[4];
    float notaS;
    float notaFinal;
    char NomeAluno[50];
    char situacao[10];
}Aluno;

void calcNota(Aluno *alunos);

void subsNota(Aluno *alunos);

void exibirNota(Aluno *alunos);

int qntdAlunos;

float calcMediaSala(Aluno *alunos);


int main() {
   char ch;
   Aluno *alunos;

   int i = 0, j;

   printf("Por favor, informe a quantidade de alunos: ");
   scanf_s("%d", &qntdAlunos);

   alunos = (Aluno*)malloc((qntdAlunos) * sizeof(int));


   /*LAÇO RESPONSÁVEL POR COLETAR DADOS DOS ALUNOS, DE ACORDO COM A 
   QUANTIDADE INFORMADA*/

   while(i < qntdAlunos){
        rewind(stdin);

        printf("Nome do aluno(a): ");
        gets(alunos[i].NomeAluno);

        fflush(stdin);

        printf("RA: ");
        scanf_s("%i", &alunos[i].ra);

        for (j = 0; j < 4; j++)
        {
            printf("Nota %i: ", (j+1));
            scanf_s("%f", &alunos[i].nota[j]);
        }

        printf("Nota Substituta: ");
        scanf_s("%f", &alunos[i].notaS);

        printf("\n");
        i++;
   }

   subsNota(alunos);
   calcNota(alunos);
   exibirNota(alunos);

   printf("Media da sala: %.2f", calcMediaSala(alunos));

   return 0;
}

void calcNota(Aluno *alunos) {
    int i = 0;

    while (i < qntdAlunos) {
        alunos[i].notaFinal = ((alunos[i].nota[0] * 1) +      (alunos[i].nota[1] * 2) + (alunos[i].nota[2] * 3) + (alunos[i].nota[3] * 4)) / 10;
        if(alunos[i].notaFinal >= 5)
            strcpy(alunos[i].situacao,"Aprovado");
        else
            strcpy(alunos[i].situacao,"Reprovado");
        i++;
    }
}

void subsNota(Aluno *alunos) {
    int posAux, i = 0, j;
    float menorNota = 0;

    while (i < qntdAlunos) {
        for (j = 0; j <= 3; j++) {
            if (menorNota == 0) {
                menorNota = alunos[i].nota[j];
                posAux = 0;
            }
            else
            {
                if (alunos[i].nota[j] < menorNota) 
                {
                    menorNota = alunos[i].nota[j];
                    posAux = i;
                }
            }
        }
        if(menorNota < alunos[i].notaS)
        alunos[i].nota[posAux] = alunos[i].notaS;

        menorNota = 0;

       i++;
   }
}

void exibirNota(Aluno *alunos) {
    int i = 0, j;

    printf("========Notas finais dos alunos\n\n\n========");
    while (i < qntdAlunos) {
        printf("===================================\n");
        printf("Nome: %s\n", alunos[i].NomeAluno);
        printf("Ra: %i\n", alunos[i].ra);

        for (j = 0; j <= 3; j++) 
            printf("Nota %i:  %.2f\n", (j + 1), alunos[i].nota[j]);

        printf("Nota Substituta: %.2f\n", alunos[i].notaS);
        printf("Media do aluno: %.2f\n", alunos[i].notaFinal);
        printf("Situacao: %s\n", alunos[i].situacao);   
        printf("===================================\n\n");
        i++;
    }
}

float calcMediaSala(Aluno *alunos) {
    float notaTotalAlunos = 0, mediaSala;
    int i = 0;

    while (i < qntdAlunos) {
        notaTotalAlunos += alunos[i].notaFinal;
        i++;
    }
    mediaSala = notaTotalAlunos / qntdAlunos;
    return mediaSala;
}
  • 2

    Devc++ is not a compiler, read this: http://answall.com/q/101691/101. It is very bad, one of the reasons is this, it works which it should not. It tries to be easier but shreds people’s heads. We can only help with more information. Actually it would be better to make a [mcve] to isolate the problem. Maybe even find the solution by doing this.

  • yes, but college requires that the code be presented in this tool. I know it is bad, but I have no option. The strange thing is that this same no problem code in vs 2015, only in dev c++. has any idea what this is?

  • I almost can’t believe someone teaches you to use absurd things like that.

  • Yeah, you can’t really believe it.

1 answer

1

Once your school asks you to run Devc++ change the build settings to be compiled in VS, your school has asked for the IDE and not the specified compiler ;D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.