How do I input names properly in a script?
8 ビュー (過去 30 日間)
古いコメントを表示
I want it to say "Davis's BODYMASSINDEX" when I type it into the command window, but I don't know how?
The stuff below is what I typed into a script
height=input('enter your height in feet:');
weight=input('enter your weight in pounds:');
name=input('enter your first name:','s');
BODYMASSINDEX = weight/(height^2)
0 件のコメント
回答 (2 件)
KSSV
2023 年 2 月 8 日
height=input('enter your height in feet:');
weight=input('enter your weight in pounds:');
name=input('enter your first name:','s');
BODYMASSINDEX = weight/(height^2) ;
fprintf('%s BODYMASSINDEX = %f\n',name,BODYMASSINDEX)
3 件のコメント
KSSV
2023 年 2 月 8 日
USe this:
fprintf('%s''s BODYMASSINDEX = %f\n',name,BODYMASSINDEX)
Walter Roberson
2023 年 2 月 8 日
or
fprintf("%s's BODYMASSINDEX = %f\n",name,BODYMASSINDEX);
Tushar Behera
2023 年 2 月 8 日
編集済み: Tushar Behera
2023 年 2 月 8 日
Hi brandon
Do you want to display something like "Davis's BODYMASSINDEX" after you have input the name and another variable?
f yes then you can use the "disp" function to display that. For example:
height=input('enter your height in feet:')
weight=input('enter your weight in pounds:')
prompt = 'Enter your name: ';
name = input(prompt, 's');
BODYMASSINDEX = weight/(height^2)
disp(name + "'s BODYMASSINDEX: " + (BODYMASSINDEX))
I hope this resolves your question.
Regards,
Tushar
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!