Making An Output Display Twice What the Input Was

3 vues (au cours des 30 derniers jours)
Ava Beaugrand
Ava Beaugrand le 17 Sep 2020
Réponse apportée : Rik le 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 commentaires
Ava Beaugrand
Ava Beaugrand le 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 le 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.

Connectez-vous pour commenter.

Réponses (1)

Rik
Rik le 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].

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by