% Programming Concepts for Mechanical Engineers % So you want my phone number and my BMI? How shallow can you get? % Title: Finding the body mass index of a person, classifying their health and recommending a target weight. % Background: In 1998, the federal government developed the body mass index (BMI) to determine ideal weights. % Body mass index is calculated as 703 times the weight in pounds divided by the square of the height in inches, % the obtained number is then rounded to the nearest whole number % Hint: 23.5 will be rounded to 24; 23.1 will be rounded to 23; 23.52 will be rounded to 24). % % Specifications: % Exercise1: Assign a value to weight in lbs, and height in inches and then calculate BMI as a rounded integer. %Exercise 1 weight=180 height=69 bmi=weight/height^2*703.0 bmi=round(bmi) % Exercise 2: Assign a value to weight in lbs, and height in inches and then % calculate BMI as a rounded integer. % If the BMI is not between 19 and 25 (both not included), print out a message % saying that “Your BMI does not correspond to a healthy weight!”. %If the BMI is between 19 and 25 (both inclusive), then %print out a message box saying, “Your BMI corresponds to a healthy weight!” %Exercise 2 weight=180 height=69 bmi=weight/height^2*703.0 bmi=round(bmi) if (bmi<19 | bmi>25) disp('Your BMI does not correspond to a healthy weight') else disp('Your BMI corresponds to a healthy weight!') end % Exercise 3: Assign a value to weight in lbs, and height in inches and then % calculate BMI as a rounded integer. Output a variable called healthy as % 0 if the person's BMI <19 (underweight) % 1 if the person’s BMI is 19?BMI?25 (healthy) % 2 if the person's BMI is 2530 (obese) % Use fprintf command with explanation for the inputs and outputs weight=180 height=69 bmi=weight/height^2*703.0 bmi=round(bmi) if (bmi<19) healthy=0 end if (bmi>=19 & bmi<=25) healthy=1 end if (bmi>25 & bmi<=30) healthy=2 end if (bmi>30) healthy=3 end fprintf('\nWeight of person =%6.2f lbs',weight) fprintf('\nHeight of person =%6.2f inches',height) fprintf('\nYour BMI is =%g ',bmi) if healthy==0 fprintf('\n You are underweight') end if healthy==1 fprintf('\n You are healthy weight') end if healthy==2 fprintf('\n You are overweight') end if healthy==3 fprintf('\n You are obese') end %Exercise 3 ALTERNATIVE weight=180 height=69 bmi=weight/height^2*703.0 bmi=round(bmi) if (bmi<19) healthy=0 elseif (bmi>=19 & bmi<=25) healthy=1 elseif (bmi>25 & bmi<=30) healthy=2 else healthy=3 end fprintf('\nWeight of person =%6.2f lbs',weight) fprintf('\nHeight of person =%6.2f inches',height) fprintf('\nYour BMI is =%g ',bmi) if healthy==0 fprintf('\n You are underweight') elseif healthy==1 fprintf('\n You are a healthy weight') elseif healthy==2 fprintf('\n You are overweight') elseif healthy==3 fprintf('\n You are obese') end % Exercise 4: Assign a value to weight in lbs, and height in inches and then % calculate BMI as a rounded integer. Output a variable called healthy as % 0 if the person's BMI <19 (underweight) % 1 if the person’s BMI is 19?BMI?25 (healthy) % 2 if the person's BMI is 2530 (obese) % Output also a variable hw for healthy weight in rounded integer lbs for all the conditions. % Use fprintf command with explanation for the inputs and outputs weight=180 height=69 bmi=weight/height^2*703.0 bmi=round(bmi) % You can use 4 separate if-end statements also. if (bmi<19) healthy=0 hw=19*height^2/703 elseif (bmi>=19 & bmi<=25) healthy=1 elseif (bmi>25 & bmi<=30) healthy=2 hw=25*height^2/703 else healthy=3 hw=25*height^2/703 end hw=round(hw) fprintf('\nWeight of person =%6.2f lbs',weight) fprintf('\nHeight of person =%6.2f inches',height) fprintf('\nYour BMI is =%g ',bmi) if healthy==0 fprintf('\nYou are underweight. Your target weight is =%6.0f lbs',hw) elseif healthy==1 fprintf('\nYou are a healthy weight. Your target weight is =%6.0f lbs',hw) elseif healthy==2 fprintf('\nYou are overweight. Your target weight is =%6.0f lbs',hw) elseif healthy==3 fprintf('\nYou are obese. Your target weight is =%6.0f lbs',hw) end