Wenn Sie sich für Gesundheit und Technologie begeistern, sind Sie vielleicht daran interessiert, Ihren Body-Mass-Index (BMI) mit C-Code zu berechnen. Der BMI wird unter Verwendung Ihres Körpergröße-zu-Gewicht-Verhältnisses berechnet und berücksichtigt manchmal Ihr Alter und Geschlecht. Laut dem Weight-control Information Network kann ein hohes BMI Sie einem größeren Risiko für bestimmte Krebsarten, koronare Herzkrankheit, Gallenblasenerkrankung, Arthrose und Schwangerschaftskomplikationen aussetzen. Ein BMI von 18,5 bis 24,9 gilt als gesündester, während ein BMI von 25 bis 29,9 und 30 oder höher als übergewichtig bzw. fettleibig gelten.
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 }

www.alskrankheit.net © Gesundheitswissenschaften