Making An Output Display Twice What the Input Was

3 Ansichten (letzte 30 Tage)
Ava Beaugrand
Ava Beaugrand am 17 Sep. 2020
Beantwortet: Rik am 17 Sep. 2020
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 Kommentare
Ava Beaugrand
Ava Beaugrand am 17 Sep. 2020
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 am 17 Sep. 2020
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 17 Sep. 2020
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].

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by