Exercise URI 1005: Correction of C code (simple mean)

1

QUESTION: When I started my code in the URI, it returned " Wrong answer (60%)" . Below are the description of the exercise and the code entered.

What's missing? What code?

Mycode:

doubleA,B,MEDIA;do{scanf("%lf", &A);

}while(A<0 || A>10);

do{
      scanf("%lf", &B);

}while(B<0 || B>10);


MEDIA=(A+B)/2;

printf("MEDIA = %.5lf\n", MEDIA);
    
asked by anonymous 12.08.2016 / 21:34

1 answer

2
The main mistake in your code is you're doing a simple average and in this case it has to be weighted at least I guess because they give weights to the notes. I made a code, tested the examples and it worked perfectly. If you do not understand something ask.

#include <stdio.h>
#include <stdlib.h>

int main()
{
   double nota_A,nota_B,media;

   do
   {
       printf("\nDigite a nota A (0 a 10.0): ");
       scanf("%lf",&nota_A);

       if(nota_A < 0 || nota_A > 10.0)
           printf("Nota inválida tente novamente\n");

   }while(nota_A < 0 || nota_A > 10.0);

   do
   {
       printf("\nDigite a nota B (0 a 10.0): ");
       scanf("%lf",&nota_B);

       if(nota_B < 0 || nota_B > 10.0)
          printf("Nota inválida tente novamente\n");

   }while(nota_B < 0 || nota_B > 10.0);

   media = ((nota_A*3.5)+(nota_B*7.5))/(3.5+7.5); // Aqui é uma media ponderada e não uma media simples devido às notas terem pesos

   printf("\nA média das notas A e B é de %.5lf",media); // coloquei %.5lf porque eles pedem 5 casas decimais 

return 0;
}
    
12.08.2016 / 22:09