Question: Week 4 Lab For this week's program, you'll ask the user to enter a date, then using a bunch of if else statements, you'll determine
Week Lab
For this week's program, you'll ask the user to enter a date, then using a bunch of if else statements, you'll determine what day of the week the date fell on
For instance, if the user enters the date your program will determine that was a Saturday. You'll probably want to ask for the month, day, and year with three separate inputs.
Not a lot of problem solving this week, just lots of if else statements to work through. The following describes how to calculate the day of the week based on the date. will be used throughout the explanation.
Start with the last two digits of the year, in this case divide by and get rid of the remainder, then add this number back onto the last two digits of the year, We'll come back for this later.
The next number we need is based on the month entered. We'll use
if the month is April or July
if the month is January or October
if the month is May
if the month is August
if the month is February, March, or November
if the month is June
if the month is September or December
For March we'll use
The next number we need will be based on the century
for the s or s
for the s or s
for the s or s
for the s or s
For we'll use
You will need to subtract one if you have a date in January or February of a leap year. We won't subtract anything since wasn't a leap year.
Now that we've done all that, we going to add the numbers we got from the Year, Month, Century, and the actual date, in this case, then we'll subtract one for January or February of a leap year. Next we'll mod the result by to find the day of the week, where represents Saturday and represents Friday. mod is so was a Saturday. So that it looks nice, your final output should be something like was a Saturday.
In case you didn't know, a leap year occurs in a year that is evenly divisible by unless the year is also evenly divisible by then it's not a leap year, unless the year is also evenly divisible by then it's back to a leap year.
Using C
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
