Question
in C language/ in visual studio 2015 Day of the Week Write a program to ask the user for the year, month, and day, and
in C language/ in visual studio 2015
Day of the Week Write a program to ask the user for the year, month, and day, and then display the day of the week for the date entered. You will first need to get the year and validate that the year is greater than 1582. Then you will need to get the month (as a number) and validate that the month is between 1 and 12 inclusive. Then you will need to determine how many days are in the month that was entered. To do so, you will first need to know if the year is a leap year or not (to know how many days are in February, in case that was the month entered) and then you can decide how many days are in the month entered. Then you will need to get the day (entered as a number) and validate that the day is between 1 and the number of days in that particular month. If any of the validations fail, the program should end. Before using the below formula to determine the day of the week, you must first convert January or February to the previous year and add 12 to the month number. For example, if the year and month entered was 2002 and 2 (February), you would change this to 2001 and 14. The formula used to determine the day of the week is: D + 2 * M + (int)(.6 * (M + 1)) + Y + (Y / 4) - (Y / 100) + (Y / 400) + 2 If you then divide the number produced by the above formula by 7, the remainder will indicate which day of the week it is, where 0 is Saturday, 1 is Sunday Finally, using a switch statement, store just the day of the week in a string variable, and then after the switch block, display the day of the week. Create (and use) constants for: The maximum invalid year (1582) The following months o Jan (1) o Feb (2) o Apr (4) o Jun (6) o Sep (9) o Nov (11) Hints: Create a Boolean variable to indicate whether the year is a leap year or not (and default it to false not a leap year) Create an integer variable for the number of days in a month (and default it to 31 the number of days in most months) Create a string variable that can hold 10 characters for the name of the day of the week (9 characters for the longest day (Wednesday) plus 1 character for the ending null character) When comparing for equality, remember to use 2 equal signs Use the modulo operator (%) to get the remainder after integer division Use the strcpy() function to assign the name of the day of the week to the string variable (and dont forget to include the string.h library) Counting the validation decisions and the ending switch block, there should be 7 decisions in the program Dont forget the blank line before Press any key to continue Example Run #1: (bold type is what is entered by the user) Enter a year (after 1582): 1963 Enter a month (1-12): 11 Enter the day (1-30): 22 The day of the week was Friday. Example Run #2: Enter a year (after 1582): 1969 Enter a month (1-12): 7 Enter the day (1-31): 20 The day of the week was Sunday. Example Run #3: Enter a year (after 1582): 1492 The year entered was not after 1582. Example Run #4: Enter a year (after 1582): 2017 Enter a month (1-12): 14 The month entered was not between 1 and 12 inclusive. Example Run #5: Enter a year (after 1582): 2017 Enter a month (1-12): 2 Enter the day (1-28): 30 The day entered was not between 1 and 28 inclusive. Example Run #6: Enter a year (after 1582): 2000 Enter a month (1-12): 2 Enter the day (1-29): 29 The day of the week was Tuesday. The example runs show EXACTLY how your program input and output will look.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started