How to fix multiple errors in this code?

Asked

Viewed 107 times

3

inserir a descrição da imagem aqui

I’m making a code that needs to contain 3 vectors (number one. enrollment, grade 1 and grade 2), relative to 6 students, which needs to be included:

  • the final grade of each student;
  • class average;
  • o Núm. of students with grades below the class average.

I made the code as far as I know, but it did not compile, (some error in variable declaration vetor). And print table style as done?

#include <stdio.h>

int main ()

{
float nota1 [6], nota2 [6], nf, medturma;
  int nm [6];
int i;

for (i=0;i<=6; i++);
{
         printf("Informe o número de matrícula %d :", i);
         scanf("%d", &nm[i]);

      printf("Informe a nota 1 do aluno %d:", i);
      scanf("%f", &nota1[i]);

     printf("Informe a nota 2 do aluno %d:", i);
    scanf("%f", &nota2[i]);
}

for (i=0; i<=6; i++)
{
    nf= (nota1[i] + nota2[i])/2;
}
    printf("A nota final de cada aluno é :",i);

    medturma=nf[i]/6;
    printf("A media da turma foi %f:", i);


    if (nf<medturma)
        printf("Notas abaixo da média %f:", i);


    }
  • the error is occurring because on line 28 you are passing the variable nf as if it were a vector, in case you should declare it above as nf[6] so that it could work, that was just the compilation analysis, fixing this it will compile

  • The error still persists.

  • It is duplicated: http://answall.com/questions/86842/como-usar-vectors

  • Can you help me? That hour I sent via cel. the image (I had no way to send)

  • @moustache the url looks the same..

  • Explain what the program should do. It does not even compile, it has a huge amount of errors. Mainly the second part is very confusing.

  • program to read and store (in three vectors) the Matricula Number (integer), Nota1 (real) and Nota2 (real) of each student in a class of 6 students. Calculate the final grade of each student, the class average, the number of students with a final grade lower than the average. Print at the end all data involved table style

  • @user32720 I realized you only gave one vote until today. Did you know you can vote for everything on the site? Anything that helped you with your questions, or even any other questions. And you can accept an answer as the most correct in every question you’ve ever asked. You are not obliged to do this, but it is interesting for everyone who does. It ranks and indicates better what was useful to you. Of course, you shouldn’t vote for things you don’t consider useful or that didn’t help. See [tour] to better understand.

Show 3 more comments

2 answers

3


The question is inconsistent but I did what I could:

#include <stdio.h>

int main () {
    float nota1[6], nota2[6], nf = 0;
    int nm[6];
    for (int i = 0; i < 6; i++) {
        printf("\nInforme o número de matrícula %d:", i);
        scanf("%d", &nm[i]);
        printf("\nInforme a nota 1 do aluno %d:", i);
        scanf("%f", &nota1[i]);
        printf("\nInforme a nota 2 do aluno %d:", i);
        scanf("%f", &nota2[i]);
    }
    printf("\nMatricula Nota1 Nota2 Nota final\n");
    float notaTotalALunos = 0;
    for (int i = 0; i < 6; i++) {
        nf = (nota1[i] + nota2[i]) / 2;
        notaTotalALunos += nf;
        printf("%d         %2.2f  %2.2f  %2.2f\n", nm[i], nota1[i], nota2[i], nf);
    }
    float medturma = notaTotalALunos / 6;
    printf("A media da turma foi: %2.2f\n", medturma);
    int alunosAbaixoDaMedia = 0;
    for (int i = 0; i < 6; i++) if ((nota1[i] + nota2[i]) / 2 < medturma) alunosAbaixoDaMedia++;
    printf("Notas abaixo da média %d:", alunosAbaixoDaMedia);
 }

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

There was a huge amount of mistakes that I wouldn’t even know where to start. I’m pretty sure it still doesn’t do what it’s wanted but it’s closer. Besides, this may be a way of doing an exercise but it would never be done this way in a real program.

The style was bad and I improved but could have improved more, I didn’t want to overstate the code already written.

If you have specific questions about how each thing works, you will open specific questions.

  • Thanks for the help! Both Abriel and Bigown! However, the first program has variables that I have not studied yet!

2

Solution implemented in C++:

#include <iostream>
using namespace std;

int main(){

float n1[6],n2[6],mediaTurma = 0;
int nrMatricula[6], maxCad = 2, mediaInferior = 0 ;

for(int i = 0 ;i < maxCad;i++){
    cout << "Informe o numero de Matricula "<< i+1 << " : ";
    cin >> nrMatricula[i];
    cout << "Informe a nota da  N1: ";
    cin >> n1[i];
    cout << "Informe a nota da  N2: ";
    cin >> n2[i];
}

for(int i = 0; i < maxCad;i++){
    float mediaAluno = (n1[i] + n2[i])/2;
    cout << "No. Matricula: " << nrMatricula[i] << endl;
    cout << "Nota 01: " << n1[i] << endl;
    cout << "Nota 02: " << n2[i] << endl;
    cout << "Nota Final: " << mediaAluno << endl;
    mediaTurma += mediaAluno;
    if(mediaAluno < 7){
       mediaInferior++;
    }
 }
 cout << "A media da turma e: " << mediaTurma/maxCad << endl;
 cout << "Número de Alunos com nota final inferior a media: " <<  mediaInferior << endl;
 return 0;
}

Browser other questions tagged

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