How do I input names properly in a script?

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일

0 개 추천

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

Brandon
Brandon 2023년 2월 8일
Thank you, but how do I get the name to have an apostrophe and "s" after the name like
David's or Micheal's
USe this:
fprintf('%s''s BODYMASSINDEX = %f\n',name,BODYMASSINDEX)
or
fprintf("%s's BODYMASSINDEX = %f\n",name,BODYMASSINDEX);

댓글을 달려면 로그인하십시오.

Tushar Behera
Tushar Behera 2023년 2월 8일
편집: Tushar Behera 2023년 2월 8일

0 개 추천

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

제품

릴리스

R2022a

질문:

2023년 2월 8일

편집:

2023년 2월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by