Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BMI_Calculator.cs
- //Console BMI calculator
- using System;
- namespace BMI_Calculator
- {
- class program //defines class as program (Class program start)
- {//Main Method Start
- public static void Main ( string[] args )
- {
- decimal Height; //Set's the variables for Height and Weight input
- decimal Weight; //and the output variable for BMI using decimal
- decimal BMI; //because needed real value for input and output i.e: 1.91m.
- 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.
- Height = Convert.ToDecimal (Console.ReadLine ()); //Allows user to input data and converts to decimal and stores in the Height variable for later use.
- Console.WriteLine ("Please enter your weight in Kilograms ex. 85 (85kg)"); //Writes on the screen asking for user to input their weight in kilograms
- Weight = Convert.ToDecimal (Console.ReadLine ()); //Allows user to input data and converts to decimal and stores in the Weight variable for later use.
- BMI=Weight/Height/Height; //Internal calculation to work out the BMI variable this is done by
- //retrieving the Weight variable and dividing it by the Height Variable twice
- 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
- if (BMI <20) //the if statement is used to give to a differnt output depending on the result of BMI variable.
- 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
- 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
- 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.");
- if (BMI >30)
- 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.");
- if (BMI >20 && BMI <25)
- 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.");
- } // End method main.
- }//Ends class program.
- }
Add Comment
Please, Sign In to add comment