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
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 FinSiFinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
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.
Related examples
Quadratic Equation
Solves ax² + bx + c = 0, with real or complex roots.
IntermediateLeap Year
Applies the calendar rules to tell whether a year is a leap year.
IntermediateCoffee Shop Menu
Pick a drink from the menu and get the total to pay.
Beginner