Write a Matlab script that asks a group of up to 50 members
Write a Matlab script that asks a group of up to 50 members to enter their height (in cm) and their weight (in kg). The script should work as follows: Prompt the user to enter the two values If any of the input values is 0, the program stops asking for more data Read in the input from the user, storing it in an appropriate variable. Repeat steps for the next member, stop when the 50th member is done. Extend the previous script so that it calculates the body mass index of each member. It is defined by the formula BMI = Weight(kg)/Height(m)^2. If the BMI is in the range 25-29.99 the member is overweight, and if it is 30 or above it is classified as obese. If the member is overweight or obese your script should print a warning message to the user showing their BMI value and their category.
Solution
a) Height and weight data entry :
clear all;
clc;
h=zeros(50,1);
w=zeros(50,1);
for i=1:50
disp(i);
h(i)=input(\'Enter Height(in cm) : \');
if h(i)==0
break;
end
w(i)=input(\'Enter Weight(in kg) : \');
if w(i)==0
break;
end
clc;
end
2) BMI calculation included :
clear all;
clc;
h=zeros(50,1);
w=zeros(50,1);
BMI=zeros(50,1);
for i=1:50
disp(i);
h(i)=input(\'Enter Height(in cm) : \');
if h(i)==0
break;
end
w(i)=input(\'Enter Weight(in kg) : \');
if w(i)==0
break;
end
BMI(i)=w(i)/(h(i)^2/10000);
if BMI(i)<29.99 && BMI(i)>25
disp(\'overweight\');
disp(BMI(i));
disp(\'press enter\');
pause;
elseif BMI(i)>30
disp(\'obese\');
disp(BMI(i));
disp(\'press enter\');
pause;
end
clc;
end
