2
I am doing an exercise with the C language to calculate the BMI, there is no error in the compiler but the result goes wrong, I have already looked at the code and I do not find the error at all.
The code is as follows::
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL,"PORTUGUESE");
printf("Claculo de imc\n");
//variaveis peso e altura
double peso;
double altura;
printf("Por favor digite seu peso: ");
scanf("%f",&peso);
printf("por favor digite sua altura: ");
scanf("%f",&altura);
double imc;
imc = peso/(altura *altura );
printf("Seu imc é de %.2f",imc);
system("pause");
return 0;
}
Change printf formats from
f
forlf
and use stitch instead of comma when reporting weight/height. I did this and it worked here.– Leonardo Santos
@Leonardo do scanf, no? :-)
– lemoce
Yes, both (printf and scanf).
– Leonardo Santos
Or change the variables to float, but ai loses in accuracy.
– MarceloBoni
You have to consider the sex of the person tbm and make the adjustment in the formula.
– gato
A micro optimization would declare all variables in one line
– MarceloBoni
@Marceloboni, which won’t make any difference. I think you already have an answer for this, but how can I not find the duplicate, if no one can find who will answer? Leonardo? I didn’t even question other small problems in code that’s more style.
– Maniero