Borrar filtros
Borrar filtros

How do I prompt a user for their name and age, then display a sentence

57 visualizaciones (últimos 30 días)
Gen
Gen el 16 de Sept. de 2020
Respondida: Samiu Haque el 16 de Sept. de 2020
I am so lost on this and I know it’s very simple I want to prompt a user for their name and their age. I then want to take their age and add a number, 5. Then I wold like to display a sentence that says “hello (name) in 5 years you will be (age+5)

Respuestas (2)

Image Analyst
Image Analyst el 16 de Sept. de 2020
Hint: Use input() and fprintf():
userResponse = input(...........................
fprintf('Hello %s in ......................\n', variable1, variable2);
See if you can finish it.
  1 comentario
Gen
Gen el 16 de Sept. de 2020
This is not homework. It's an old test that I could not do and I'm just atempting it because I should have know how to do it but could not figure it out. No, I can not finish it, because I do not know what I'm doing. I have been at this for multiple hours. I have zero experience with code and matlab and do not know even what %s means.

Iniciar sesión para comentar.


Samiu Haque
Samiu Haque el 16 de Sept. de 2020
Maybe this is what you want-
name = input('Enter your name: ','s');
age = input('Enter your age: ');
fprintf('Hello %s in 5 years you will be %d\n',name,age+5)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by