Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function BMI()
- % This program calculates the BMI of a person. It allow for the program to
- % be used worldwide and takes account for the Imperial and Metric systems
- % for easy use.
- clc;
- clear;
- % Displays the information to the user about the systems which can be used.
- disp(' --- BMI Calculator --- ');
- disp('Please choose the measurement system you would like to use:');
- disp(' 1. Kilograms/Centimeters');
- disp(' 2. Pounds/Inches');
- disp(' 3. Pounds/Feet');
- disp(' 4. Stone/Inches');
- optn = input('Please choose which system you would like to use. [1/2/3/4]: ');
- % Checks to see which system the user has chosen and asks for the variables
- % accordingly.
- if optn == 1
- disp('Please input the your Weight, and Height');
- w = input('Your Weight(Kg) is? ');
- h = input('Your Height(cm) is? ');
- h1 = h / 100;
- BMI = round(w / h1^2);
- pause(1)
- elseif optn == 2
- disp('Please input the your Weight, and Height');
- w = input('Your Weight(lbs) is? ');
- h = input('Your Height(in.) is? ');
- BMI = round((w / (h^2)*703));
- pause(1)
- elseif optn == 3
- disp('Please input the your Weight, and Height');
- w = input('Your Weight(lbs) is? ');
- h = input('Your Height(ft) is? ');
- BMI = round((w / (h^2)*4.88));
- pause(1)
- elseif optn == 4
- disp('Please input the your Weight, and Height');
- w = input('Your Weight(st) is? ');
- h = input('Your Height(in.) is? ');
- BMI = round((w / (h^2)*9840));
- pause(1)
- else
- disp('Please choose a valid option.')
- pause(2.5)
- BMI();
- end
- % Displays the users BMI
- disp(['Your BMI is: ', num2str(BMI)])
- % Displays a message to the user about where they fall on the BMI scale and
- % tells the user what their BMI means.
- if BMI <= 18
- disp('You are very underweight and possibly malnourished.')
- elseif BMI <20
- disp('You are underweight and could afford to gain a little weight.')
- elseif BMI <=25
- disp('You have a healthy weight range for young and middle-aged adults.')
- elseif BMI <=30
- disp('You are overweight')
- elseif BMI > 30
- disp('You are obese')
- end
Add Comment
Please, Sign In to add comment