Calcula el IMC con Código C: Guía Práctica

Si te apasionan la salud y la tecnología, te puede interesar calcular tu índice de masa corporal (IMC) usando código C. El IMC se calcula con tu ratio altura-peso y a veces considera edad y sexo. Según la Red de Información sobre Control de Peso, un IMC alto puede aumentar riesgo de ciertos cánceres, cardiopatía coronaria, enfermedad de vesícula, artrosis y complicaciones en el embarazo. IMC 18,5-24,9 es más saludable; 25-29,9 sobrepeso; ≥30 obesidad.

Lo que necesitarás

  • Báscula para adultos, en libras
  • Cinta métrica

Instrucciones

Código C++ para Windows y Linux/Unix

  1. Configura tu código C++ de IMC en Windows o Linux/Unix.

  2. Ve a www.arachnoid.com para configurar tu código C++ de IMC en Windows.

  3. Ve a la página de tutorial C++ de www.arachnoid.com para configurar en Unix.

  4. Ejecuta las líneas de código 1 a 59 en la plataforma apropiada:

    01 using System;
    02 using System.Collections.Generic;
    03 using System.ComponentModel;
    04 using System.Data;
    05 using System.Drawing;
    06 using System.Linq;
    07 using System.Text;
    08 using System.Windows.Forms;
    09
    10 namespace BMIApp
    11 {
    12 public partial class Form1 : Form
    13 {
    14 public Form1()
    15 {
    16 InitializeComponent();
    17 }
    18
    19 private void btnCalculate_Click(object sender, EventArgs e)
    20 {
    21 double weght = string.IsNullOrEmpty(txtWeight.Text) ? 1 : double.Parse(txtWeight.Text);
    22 double height = string.IsNullOrEmpty(txtHeight.Text) ? 1 : double.Parse(txtHeight.Text);
    23
    24 if (weght == 0)
    25 {
    26 MessageBox.Show("Results will be inaccurate. Weight is not a valid number.");
    27 }
    28 if (height == 0)
    29 {
    30 MessageBox.Show("Results will be inaccurate. Height is not a valid number.");
    31 }
    32
    33 double vmult = cboWeightUnits.SelectedItem.ToString() == "pounds" ? 2.204 : 1;
    34 double hmult = cboHeightUnits.SelectedItem.ToString() == "inches" ? 0.0254 : 1;
    35
    36 double BMI = Math.Round(((weght / vmult) / ((height * hmult) * (height * hmult))) * 10) / 10;
    37
    38
    39 string BMI_description = string.Empty;
    40 if (BMI < 16.5)
    41 BMI_description = "severely underweight";
    42 else if (BMI >= 16.5 && BMI < 18.5)
    43 BMI_description = "underweight";
    44 else if (BMI >= 18.5 && BMI < 25)
    45 BMI_description = "normal";
    46 else if (BMI >= 25 && BMI <= 30)
    47 BMI_description = "overweight";
    48 else if (BMI > 30 && BMI <= 35)
    49 BMI_description = "obese";
    50 else if (BMI > 35 && BMI <= 40)
    51 BMI_description = "clinically obese";
    52 else
    53 BMI_description = "morbidly obese";
    54
    55
    56 txtResult.Text = string.Format("Your Body Mass Index (BMI) is: {0}. This would be considered {1}.", BMI, BMI_description);
    57 }
    58 }
    59 }

Encuentra tu IMC

  1. Toma tu peso en libras e introdúcelo en la casilla de peso de la calculadora C++ de IMC.

  2. Mide tu altura en pulgadas e introdúcela en la casilla de altura.

  3. Determina si tu clase de peso es saludable, sobrepeso u obesidad según la salida de la calculadora.