How to decrease, taking only one number from the other value?

0

In the final value was to have the total of the notes greater than 7, another condition would be that the user has to enter a number between 0 and 10, then any number outside this would give "invalid message", and would have its decrement, so for example if the user types: 11, 9 and 8; instead of appearing in total 3 notes > 7, it would only appear 2 ... But I can not do it, so if anyone knows how to solve it, or another way to do it, talk there coments ... Thank you in advance. >

#include <stdio.h> 

int main () { 
    int aluno, i, alunosComNotaMaiorQueSete = 0;
    float nota;

    printf("Quantos alunos fizeram a prova? ");
    scanf("%d", &aluno);

    for(i = 0; i < aluno; i++) { 
   
        printf("Digite a nota do aluno %d:\n", i);
        scanf("%f", &nota);

    if (nota<0 || nota>10)
   { 
        printf("\n Nota Invalida\n");
        alunosComNotaMaiorQueSete--;
   }else if(nota>7 && nota<=10) 
   {
        alunosComNotaMaiorQueSete++;
   }
    }     
    printf("Alunos com nota > 7: %d\n", alunosComNotaMaiorQueSete);

    return 0;
}
    
asked by anonymous 01.04.2018 / 02:51

1 answer

1

You do not need to decrease only sum if the note is larger. Nor do you need to say that the < 10 in the else if so it will only pass to the else if if the condition of the first if is true.

#include <stdio.h> 

int main () { 
int aluno, i, alunosComNotaMaiorQueSete = 0;
float nota;

printf("Quantos alunos fizeram a prova? ");
scanf("%d", &aluno);

for(i = 0; i < aluno; i++) { 

    printf("Digite a nota do aluno %d:\n", i);
    scanf("%f", &nota);

    if (nota<0 || nota>10)
    { 
        printf("\n Nota Invalida\n");
        //codigo antigo que nao é preciso: 
        //alunosComNotaMaiorQueSete--;
    }
    else if(nota>7 /*&& nota<=10*/) 
    {
        alunosComNotaMaiorQueSete++;
    }
}        
    printf("Alunos com nota > 7: %d\n", alunosComNotaMaiorQueSete);
    return 0;
}
    
01.04.2018 / 04:06