Doing BMI calculations I’m not getting just the result 80

Asked

Viewed 85 times

1

#include <stdio.h>
#include <math.h>

int main() 
{      
    float peso,altura,imc;
    imc=0;
    printf("digite seu peso ?");
    scanf("%f",&peso);
    printf("digite sua altura? ");
    scanf("%f",&altura);
    imc= (peso/pow(altura,2 )); //usando a função pow
    printf(" IMC igual a  %10.2f ",imc);

    return 0;
}

and without using the function pow

#include <stdio.h>
#include <math.h>

int main() 
{      float peso,altura,imc;
   imc=0;
    printf("digite seu peso ?");
    scanf("%f",&peso);
    printf("digite sua altura? ");
    scanf("%f",&altura);   // usando a função pow
    imc= (peso/altura*altura) ; // sem a função pow
    printf(" IMC igual a  %10.2f ",imc);

    return 0;
}
  • 1

    Gabriel, you can edit the question and describe the problem, if you need help on how to use the tool, go to [help].

1 answer

7

In the first test it was not possible to reproduce its problem:

https://ideone.com/m4IVad


The second is basic math error.

First you divide weight by height, then you multiply by height:

     peso/altura*altura
// 1 ----^
// 2 -----------^

The result, guess what? The time will come1...


See the difference with the parentheses in the appropriate place:

imc = peso/(altura*altura);

https://ideone.com/LTEK5K


1. except for rounding differences which are not applicable in this financial year..

Browser other questions tagged

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