How to fix multiple errors in this code?

3

Iammakingacodethatneedstocontain3vectors(registrationnumber,note1andnote2),relativeto6students,whichmustinclude:

  • thefinalgradeofeachstudent;
  • theclassaverage;
  • ono.ofstudentswithagradebelowtheclassaverage.

ImadethecodeasfarasIknow,butitdidnotcompile,(someerrorinthedeclarationofthevariablevetor).Andprinttablestylehowdoyoudo?

#include<stdio.h>intmain(){floatnota1[6],nota2[6],nf,medturma;intnm[6];inti;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);


    }
    
asked by anonymous 15.09.2015 / 00:17

2 answers

3

The question is inconsistent but I did what I gave:

#include <stdio.h>

int main () {
    float nota1[6], nota2[6], nf = 0, medturma;
    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);
    }
    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);
 }

See running on ideone .

There were a lot of mistakes I would not even know where to start. I'm pretty sure you still do not do what you want but it's closer. Other than that this may be a way to do for 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, did not want to de-characterize the code already written.

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

    
15.09.2015 / 01:11
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;
}
    
15.09.2015 / 01:12