Making An Output Display Twice What the Input Was

조회 수: 3 (최근 30일)
Ava Beaugrand
Ava Beaugrand 2020년 9월 17일
답변: Rik 2020년 9월 17일
How do you multiply/modify a variable so that the value it displays is twice what the user entered?
I am asking the user to input an age and I want the output to show an age that is two times what the user entered. Can anyone please help?
  댓글 수: 5
Ava Beaugrand
Ava Beaugrand 2020년 9월 17일
I am very new to MATLAB, but my attempt to multiply the age variable can be seen within the fprintf() function on the last line. My result when I did this though gave "bp" instead of a number twice the input number value like I wanted.
Ava Beaugrand
Ava Beaugrand 2020년 9월 17일
The prompt I was given said , " This can be done by multiplying the age variable and storing it back into the same variable, or by multiplying the age variable when using it in the fprintf() statement. " but I do not know how to go about doing this.

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

답변 (1개)

Rik
Rik 2020년 9월 17일
You need to make sure you receive the input as a numeric data type, or you need to convert the string input to a double (that is a hint about which function you should be using). Currently you're multiplying the separate characters in the char array, so ['2'*2 '0'*2].

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by