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

11 views (last 30 days)
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

Accepted Answer

James Tursa
James Tursa on 11 Apr 2019
Edited: James Tursa on 11 Apr 2019
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.')

More Answers (0)

Categories

Find more on Birthdays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!