Group Abstract Group Abstract

Message Boards Message Boards

0
|
5K Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

Use "Switch" command in a "Input" function?

Posted 9 years ago

I am writing a program that asks a user for their birthdate in three separate steps: month, day and year, but where the month is given as a word, like "April". I want my program to return the date in the form "mm/dd/yyyy". This means the day will have to be output as a two digit numeral, where day 9 would be entered as 09

here is what I have created so far. I am not sure how to implement my "Input" functions into my "Switch" function.

Clear[month, day, year, monthSwitch, a];
month = Input["What is your birthday month? Such as " April ""];
day = Input[ "What day is your birthday? If the day number falls in between 1-9, please enter 0 number, such as 09 "];
year = Input[ "What year were you born in? Please enter the 4 digit year, such as 1994"]

Clear[a, month, color];
color[monthSwitch_] := (
a = monthSwitch;
Switch[a,
January, "01",
February, "02",
March, "03",
April, "04",
May, "05",
June, "06",
July, "07",
August, "08",
September, "09",
October, "10",
November, "11",
December, "12",
_, monthSwitch]);

I am not sure know how I should go about the rest of this..

POSTED BY: Brandon Davis
3 Replies

You could use:

DateString["12 January 2016", {"Month", "/", "Day", "/", "YearShort"}]
POSTED BY: Sander Huisman

Put the months in quotes, they are strings, furthermore the auxiliary variable a is not needed:

color[monthSwitch_] := 
 Switch[monthSwitch, "January", "01", "February", "02", "March", "03",
   "April", "04", "May", "05", "June", "06", "July", "07", "August", 
  "08", "September", "09", "October", "10", "November", "11", 
  "December", "12", _, monthSwitch]
POSTED BY: Sander Huisman
Posted 9 years ago

@Sander,

Thanks for the clarification. I'm pretty certain I'm going to need to now create an "If" statement that will utilize my 3 "Input" functions, "month", "day" and "year" so that I can eventually get the output of "mm/dd/yyyy", for whichever month, day and year a user enters. Am I wrong?

POSTED BY: Brandon Davis
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard