Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote