• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //BMI_Calculator.cs
2. //Console BMI calculator
3.
4. using System;
5. namespace BMI_Calculator
6. {
7.     class  program //defines class as program (Class program start)
8.         {//Main Method Start
9.             public static void Main ( string[] args )
10.                 {
11.                 decimal Height; //Set's the variables for Height and Weight input
12.                 decimal Weight; //and the output variable for BMI using decimal
13.                 decimal BMI;    //because needed real value for input and output i.e: 1.91m.
14.                 Console.WriteLine ("Please enter your height in Metres ex. 1.55 (155cm)");  //Writes on the screen asking for user to input their height in metres.
15.                 Height = Convert.ToDecimal (Console.ReadLine ());                           //Allows user to input data and converts to decimal and stores in the Height variable for later use.
16.                 Console.WriteLine ("Please enter your weight in Kilograms ex. 85 (85kg)");  //Writes on the screen asking for user to input their weight in kilograms
17.                 Weight = Convert.ToDecimal (Console.ReadLine ());                           //Allows user to input data and converts to decimal and stores in the Weight variable for later use.
18.
19.
20.                 BMI=Weight/Height/Height;                                                   //Internal calculation to work out the BMI variable this is done by
21.                                                                                             //retrieving the Weight variable and dividing it by the Height Variable twice
22.
23.                 Console.WriteLine("Your Body Mass Index is: {0:F3}", BMI);                                  //Writes on the screen the result of the BMI calculation limited to 3 decimal places to be more readable
24.                 if (BMI <20)                                                                                //the if statement is used to give to a differnt output depending on the result of BMI variable.
25.                 Console.WriteLine("This result suggests you are underweight, which can affect health.");    //if the value of BMI is less than 19 this will be displayed on the screen
26.                 if (BMI >25 && BMI <30)                                                                     //the "if (BMI >25 && BMI <30)" line checks if the BMI variable output is inbetween the value of 25 and 30 and gives the correct output BMI variable
27.                 Console.WriteLine("This result suggests you are overweight, which increases the risk of becoming ill with problems such as high blood pressure, heart disease and cancer.");
28.                 if (BMI >30)
29.                 Console.WriteLine("This result suggests you are obese, which increases the risk of becoming ill with problems such as high blood pressure, heart disease and cancer.");
30.                 if (BMI >20 && BMI <25)
31.                 Console.WriteLine("This result suggests you are a healthy weight for your height. Maintaining a healthy weight decreases the risk of a range of serious health problems.");
32.                 } // End method main.
33.         }//Ends class program.
34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?