Warning error: format specifies type 'double' but the argument has type 'float *', C language

Asked

Viewed 453 times

-1

Hello, I made this program to show the average between 2 numbers and show if the student was approved or not, however the result is not working.

#include <stdio.h>

int main(void) {

  float primeiraNota, segundaNota, media;

     printf("Digite a primeira nota: ");
       scanf("%f", & primeiraNota);
     printf("Digite a segunda nota: ");
       scanf("%f", & segundaNota);

    media = (primeiraNota + segundaNota)/ 2;

    if (media > 6)
      printf(" O aluno esta aprovado com a media = %f", &media);

      else
        printf(" O aluno esta reprovado com a media = %f", &media);

  return 0;
}

1 answer

3


The function printf() are receiving %f in formatting string, and this requires a variable of type double or float in the formatting list.

The Warning is happening because you are passing the address of the variable media (or float*) in the formatting list and not its content.

The right thing would be:

if (media > 6)
    printf(" O aluno esta aprovado com a media = %f", media);
else
    printf(" O aluno esta reprovado com a media = %f", media);
  • It worked, thank you very much!

Browser other questions tagged

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