Simple program to calculate school averages in C with vector

Asked

Viewed 36 times

0

Hello, I am trying to run a small program that I would like you to read a certain average, store 4 student X grades, calculate the average of those grades and compare with the minimum average grade required by the institution.

However, I am in trouble, because by showing the average of the student (and the sum of his grades) I get a very large number, which makes no sense. I am also having trouble making the score appear correctly in cmd. I am using the gcc compiler, obtained through Mingw.Follow the code.

Note: They are marking this question as already answered, but the demanding answer is not my doubt, because I am not dealing with functions and my program differs in many points from the already existing question, as for example, in the use of vector and in the use of bibilioteca locale. h. `

#include <stdio.h>
#include <locale.h>

int main(void) {

setlocale(LC_ALL, "Portuguese");


    double medias[3];
    double somaNotas;
    double media;
    double mediaInstituicao;

printf("\nPor favor digite a nota media da instituicao em questão");
scanf("%d", mediaInstituicao);

    for (int i = 0; i<=3; i++){
      int n;
      n = i+1;
        printf("\nPor favor, digite a %i º nota do aluno: \n",(i+1));
        scanf("%d",&medias[i]);
        somaNotas += medias[i];

    }

    printf("\nA soma das notas é igual À: %.2d",somaNotas);

    media = (somaNotas/4);


   printf("A média À: %.2d",media);

    if(media >= mediaInstituicao){

        printf("\nO aluno foi aprovado, não haverá necessidade de fazer a segunda prova pois sua m�dia foi %.2d");



    } else{
        printf("\nO aluno foi reprovado, ele terá de fazer a 5º prova, pois suma média foi somente %2.d", media);
    }
    return 0;

}
  • Post the complete code, with the #includes

  • Your data is of the type double but you’re trying to read and write as if they were int, ex: double media; ... scanf("%d",&medias[i]);. Adjust the writing and reading formats of your printf and scanf of %d(int) for %lf(double).

No answers

Browser other questions tagged

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