Exercise URI 1005: Code correction C (simple average)

Asked

Viewed 1,306 times

1

QUESTION: When I typed my code in the URI it returned "Wrong Answer (60%)". Below is the description of the exercise and the code entered.

What is missing? What code?

inserir a descrição da imagem aqui

My code:

double A, 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);

1 answer

2

The main error in your code is you are making a simple average and in this case it has to be weighed at least I think, because they give weights to the notes. I made a code, tested the examples and worked perfectly. If you didn’t 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;
}
  • 1

    I totally understand. I can’t believe it was just a lack of attention! Thank you very much and I’m sorry for the question, I should have revised my code with the statement, but I only read it once. Anyway, thank you!

Browser other questions tagged

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