MATLAB Answers

KR
0

How do i write an input statement asking the user to enter their birthdate as a matrix with entries of month,day, year?

Asked by KR
on 11 Apr 2019
Latest activity Commented on by KR
on 11 Apr 2019
Is this possible without using, else, if statements?
This is what i have.
clc
clear
name=input('Enter your name: ','s');
Choice=menu('Do you live in South Carolina?','yes','no');
bdayprompt=input('Enter your birthday in the format[month day year]: ');
birthdate=[bdayprompt];
fprintf('%s was born on %d.',name,birthdate)
Thanks

  0 Comments

Sign in to comment.

1 Answer

Answer by James Tursa
on 11 Apr 2019
Edited by James Tursa
on 11 Apr 2019
 Accepted Answer

If the user follows instructions, birthdate will be a vector of three numbers, so you need the format string to print out three numbers using three %d fields. E.g.,
fprintf('%s was born on %d %d %d.\n',name,birthdate)
You might make it explicit in your instructions that the user needs to type in the square brackets surrounding the three numbers. E.g.,
disp('In the following prompt, be sure to type in the square brackets surrounding your birthday numbers.')