Skip to content
ExamplesEspañolWorkspace →

Body Mass Index

Computes your BMI and classifies it as underweight, normal and so on.

Level
Intermediate
Topic:
Decisions
Concepts:
Input & output
Si
Math
Open in Codoritmo

Run, change and debug this example in your browser.

What you'll learn

The ^ operator squares the height and Redon rounds the result. Nested Si blocks inside each SiNo test the ranges one after another.

Code

bmi.psc · 22 lines
Algoritmo CalculadoraIMC    Definir peso, altura, imc Como Real    Escribir "Peso en kilogramos:"    Leer peso    Escribir "Altura en metros (por ejemplo 1.70):"    Leer altura    imc <- peso / altura ^ 2    Escribir "Tu IMC es ", Redon(imc * 10) / 10    Si imc < 18.5 Entonces        Escribir "Clasificación: bajo peso"    SiNo        Si imc < 25 Entonces            Escribir "Clasificación: peso normal"        SiNo            Si imc < 30 Entonces                Escribir "Clasificación: sobrepeso"            SiNo                Escribir "Clasificación: obesidad"            FinSi        FinSi    FinSiFinAlgoritmo

Flowchart

Each block in the flowchart matches one instruction in the code.

Algoritmo CalculadoraIMCSíNoSíNoSíNoAlgoritmo CalculadoraIMCAlgoritmo CalculadoraIMCDefinir peso, altura, imc Como RealDefinir peso, altura, imc ComoRealEscribir "Peso en kilogramos:"Escribir "Peso en kilogramos:"Leer pesoLeer pesoEscribir "Altura en metros (por ejemplo 1.70):"Escribir "Altura en metros(por ejemplo 1.70):"Leer alturaLeer alturaimc <- peso / altura ^ 2imc <- peso / altura ^ 2Escribir "Tu IMC es ", Redon(imc * 10) / 10Escribir "Tu IMC es ",Redon(imc * 10) / 10Si imc < 18.5 Entoncesimc < 18.5Escribir "Clasificación: bajo peso"Escribir "Clasificación: bajopeso"Si imc < 25 Entoncesimc < 25Escribir "Clasificación: peso normal"Escribir "Clasificación: pesonormal"Si imc < 30 Entoncesimc < 30Escribir "Clasificación: sobrepeso"Escribir "Clasificación:sobrepeso"Escribir "Clasificación: obesidad"Escribir "Clasificación:obesidad"FinAlgoritmoFinAlgoritmo

Sample run

This is what the program shows when it runs. The answers typed by the user are highlighted.

Peso en kilogramos:User answer: 68Altura en metros (por ejemplo 1.70):User answer: 1.72Tu IMC es 23Clasificación: peso normal

Challenge

Besides the category, show how many kilos are missing or extra to reach the normal range.

Show hint

The lowest healthy weight is 18.5 * altura ^ 2 and the highest is 25 * altura ^ 2.

Open in Codoritmo
  • Quadratic Equation

    Solves ax² + bx + c = 0, with real or complex roots.

    Intermediate
  • Leap Year

    Applies the calendar rules to tell whether a year is a leap year.

    Intermediate
  • Coffee Shop Menu

    Pick a drink from the menu and get the total to pay.

    Beginner