This challenge activity uses a 3rd party app Though your act
This challenge activity uses a 3rd party app. Though your activity may be recorded, a refresh may be required to update the banner to the left. Writing a nested function: BMI calculation Write a nested function CalculateBMI that assigns bmiValue given a user\'s weight and height. Use the following equations to calculate the BMI. BMI = weight in lbs midddot 703/height in inches^2 function BMI = ReportBMI(userWeight, userHeight) % userWeight: user weight in kg % userHeight: user height in centimeters kgToPounds = 2.20462; % 1 kg = 2.20462 pounds cmToInches = 0.393701; % 1 cm = 0.393701 in % Calls function with parameters weight (kg) and heigth (cm) BMI = CalculateBMI(userWeight, userHeight); % Define a nested function CalculateBMI % Function inputs: userWeight (kg), userHeight (cm) % Function output: bmiValue % function bmiValue .. % Use kgToPounds and cmToInches conversion factor % bmiValue = (weight in lbs * 703)/(height in inches^2) end Run Your Solution Code to call vour function when vou click Run
Solution
% ReportBMI.m file
function BMI = ReportBMI(userWeight,userHeight)
% userWeight: user weight in kg
% userHeight: user height in centimeters
kgToPounds = 2.20462 % 1 kg = 2.20462 pounds;
cmToInches = 0.393701 % 1 cm = 0.393701 inches;
%Calls funciton with parameters weight(kg) and height(cm)
BMI = CalculateBMI(userWeight,userHeight);
function bmiValue = CalculateBMI(userWeight,userHeight)
% Use kgToPounds and cmToInches conversion factor
userWeight = userWeight * kgToPounds;
userHeight = userHeight * cmToInches;
bmiValue = (userWeight*703)/(userHeight^2);
end
end
% demo.m file
m = ReportBMI(4,5);
disp(m)
% sample output
% 1599.8
