How do I input names properly in a script?

9 次查看(过去 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)

回答(2 个)

KSSV
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
KSSV 2023-2-8
USe this:
fprintf('%s''s BODYMASSINDEX = %f\n',name,BODYMASSINDEX)

请先登录,再进行评论。


Tushar Behera
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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by