Ask the user for their first name, last name, age and favorite color. Then use t
ID: 668029 • Letter: A
Question
Ask the user for their first name, last name, age and favorite color. Then use this information to return a display that says the following.
“Hello, (first name) (last name). You are (age) years old and your favorite color is (favorite color)!”
This is what I did.
clear
clc
M = inputdlg('What is your first name?','s');
N = inputdlg('What is your last name?','s');
O = inputdlg('How old are you?');
O = str2num(O{:});
P = inputdlg('What is your favorite color?','s');
fprintf('"Hello, %s %s. You are %i years old and your favorite color is %s!" ',M,N,O,P);
This is what I got for the answer.
Error using fprintf
Function is not defined for 'cell' inputs.
Explanation / Answer
try this :
clear
clc
M = inputdlg('What is your first name?','s');
N = inputdlg('What is your last name?','s');
O = inputdlg('How old are you?');
O = str2num(O{:});
P = inputdlg('What is your favorite color?','s');
disp(['Hello',M,N, 'Your age is:',O,'Your Favorite color is :',P)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.