Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2008-05-25
年龄: 38
帖子: 1
声望力: 0 ![]() |
![]()
原題目為:
請以程式設計說明東方人(oriental)與西方人(Occidental)之身體肥胖程度之判定方式,條件如下: a. 請先輸入身高體重或選擇人種,並判斷是否輸入正確,接著進行BMI值之判斷與計算,最後再輸出結果 b. 身高與體重必須為正值,若非正值則輸出錯誤訊息,請重新輸入 c. BMI計算方式= [體重(kg)/身高(w)]^2 d.以下為定義: 東方人 BMI<18.5=Light,18.5 <= BMI < 24.0=normal,24.0 <= BMI < 27.0=heavy, BMI > 27.0=fat 西方人 BMI<18.5=Light,18.5 <= BMI < 25.0=normal,25.0 <= BMI < 30.0=heavy, BMI > 30.0=fat e. 輸出結果格式為:依據XX人標準,BMI值為XX,屬XX情形。 以下是在下的程式,還有很多不知道如何寫的地方請各位相助!感謝了! 在下是剛入門的新手希望各位多多包含! ====================================================== % Script_BMI a = input('Please enter his/her/your kg: '); str1 = ['His/Her/Your kg is ' num2str(a)]; disp(str1); b = input('Please enter his/her/your height: '); str2 = ['His/Her/Your age is ' num2str(b)]; disp(str2); c = input('Please enter his/her/your age: ','s'); str2 = ['His/Her/Your age is ' num2str(c)]; disp(str2); race = input('Please enter a human race: ','s'); switch race case {'oriental','Oriental','ORIENTAL'}; disp('東方人'); case {'occidental','OCCIDENTAL','Occidental' }; disp('西方人'); otherwise disp('Unknow value') end BMI = (a+b)^2; if BMI < 18.5; disp('It defined Light.') elseif 18.5 <= BMI < 24.0; disp('It define Normal') elseif 24.0 <= BMI < 27.0; disp('It define Heavy') elseif BMI > 27.0; disp('It define Fat') end |
![]() |
![]() |