C number of approved students failed

Asked

Viewed 107 times

-3

Please, I need the total amount of failed and substitute students approved program

Elaborate program C to calculate and display the average of 3 students in a given discipline. The simple arithmetic mean is calculated from reading 2 notes. For each student: - display the "OK" message if the average obtained is 6 or more.

  • display the message "SUBSTITUTE if the average obtained is greater than or equal to 3 and less than 6. - display the message "DISAPPROVED" if the average obtained is less than 3.

At the end, display the amount of students approved, students who will make the replacement and students failed.

I got so far:


#include <stdio.h>

int main() {

int i;
int aprovado = 0;
int reprovado = 0;
int substitutiva = 0;

float n1,n2,m;
printf("informe as notas dos alunos: \n");

for(i=1;i<=3;i++){
    printf("\n\nnotas do aluno %i\n",i);
    scanf("%f %f", &n1,&n2);
    m=(n1+n2)/2;
    if(m>=6)
        printf("aluno aprovado - media %.2f",m);
        aprovado = aprovado++;
        else if(m>=3)
            printf("fazer substitutiva - media %.2f",m);
            substitutiva = substitutiva++;
            else
                printf("aluno reprovado - media %.2f",m);
                reprovado = reprovado++;


        }

printf("Alunos Aprovados %d", aprovado);
printf("Alunos Reprovados %d", reprovado);
printf("Alunos Substitutiva %d", substitutiva);
for(i = 1; i <=3; i++)
    
    
return 0;

}

1 answer

2

Case what must be executed on condition of a if for more than one command so you need to put the commands in a block {...}.
The operator of increment k++; is equivalent to k = k + 1; so don’t do another assignment.

#include <stdio.h>

int main() {

int i;
int aprovado = 0;
int reprovado = 0;
int substitutiva = 0;

float n1,n2,m;
printf("informe as notas dos alunos: \n");

for(i=1;i<=3;i++){
    printf("\n\nnotas do aluno %i\n",i);
    scanf("%f %f", &n1,&n2);
    m=(n1+n2)/2;
    if(m>=6) {
        printf("aluno aprovado - media %.2f",m);
        aprovado++;
    }
    else 
        if(m>=3) {
            printf("fazer substitutiva - media %.2f",m);
            substitutiva++;
        }
        else {
            printf("aluno reprovado - media %.2f",m);
            reprovado++;
        }
    }
    printf("Alunos Aprovados %d", aprovado);
    printf("Alunos Reprovados %d", reprovado);
    printf("Alunos Substitutiva %d", substitutiva);
    return 0;
}

Browser other questions tagged

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