Function CalculoIMC(Peso : real; Altura : Real) : string;
var
imc : real;
begin
try
altura := sqr(altura);
imc := peso/altura;
if (imc > 0) and (imc < 18.5)
then begin
result := 'Abaixo do Peso';
end else
if (imc >= 18.5) and (imc <= 24.9)
then begin
result := 'Peso Normal';
end else
if (imc >= 25) and (imc <= 29.9)
then begin
result := 'Sobrepeso';
end else
if (imc >= 30) and (imc <= 34.9)
then begin
result := 'Obesidade Grau I';
end else
if (imc >= 35) and (imc <= 39.9)
then begin
result := 'Obesidade Grau II';
end else
if (imc > 40)
then begin
result := 'Obesidade Grau III';
end;
except
result := 'Indefinido';
messagedlg('Ocorreu um erro durante o cálculo do IMC!' + #13 +
'Verifique se o peso e a altura da pessoa' + #13 +
'foram informados corretamente!' , MTERROR, [MBOK],0);
abort;
end;
end;
// para chamar a função
procedure TForm1.Button1Click(Sender: TObject);
begin
Label4.caption:= CalculoIMC(strtofloat(edit1.text),strtofloat(edit2.Text));
end;
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário