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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by