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 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 what day of the week the date fell on.
For instance, if the user enters the date 3/14/2015, 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. 3/14/2015 will be used throughout the explanation.
Start with the last two digits of the year, in this case 15, divide by 4 and get rid of the remainder, 154=>3, then add this number back onto the last two digits of the year, 15+3=18. We'll come back for this 18 later.
The next number we need is based on the month entered. We'll use
0 if the month is April or July
1 if the month is January or October
2 if the month is May
3 if the month is August
4 if the month is February, March, or November
5 if the month is June
6 if the month is September or December
For March we'll use 4.
The next number we need will be based on the century
0 for the 1500 s or 1900 s
2 for the 1800 s or 2200 s
4 for the 1700 s or 2100 s
6 for the 1600 s or 2000 s
For 2015, we'll use 6.
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 2015 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, 14 in this case, then we'll subtract one for January or February of a leap year. 18+4+6+14=42. Next we'll mod the result by 7 to find the day of the week, where 0 represents Saturday and 6 represents Friday. 42 mod 7 is 0, so 3/14/2015 was a Saturday. So that it looks nice, your final output should be something like 3/14/2015 was a Saturday.
In case you didn't know, a leap year occurs in a year that is evenly divisible by 4, unless the year is also evenly divisible by 100, then it's not a leap year, unless the year is also evenly divisible by 400, then it's back to a leap year.
Using C++
 Week 4 Lab For this week's program, you'll ask the user

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!