Making An Output Display Twice What the Input Was

3 visualizzazioni (ultimi 30 giorni)
Ava Beaugrand
Ava Beaugrand il 17 Set 2020
Risposto: Rik il 17 Set 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 Commenti
Ava Beaugrand
Ava Beaugrand il 17 Set 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 il 17 Set 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.

Accedi per commentare.

Risposte (1)

Rik
Rik il 17 Set 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].

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by