Question
Lab /HW 3 Write a program that reads in the following data , all entered on one line with at least one space separating them
Lab/HW 3
Write a program that reads in the following data, all entered on one line with at least one space separating them:
If any one of these three conditions occurs, only one error message should print and no further code should be executed. If everything is good so far, then continue as below:
30 days has September, April, June and November,
All the rest have 31 except February which has 28 but in a leap year has 29
Page 97 in the textbook shows code to determine a leap year. A year is a leap year if (1) its divisible by 400 OR
(2) the year is divisible by 4 AND not divisible by 100.
So, if its a leap year any day up to and including 29 is valid, otherwise 28 is the largest date in February. If February has too many days, e.g., the input is 2 29 2001, print an error message stating
2001 is not a leap year, Feb can have only 28 days
5 18 2017 is a valid date
THESE TEST CASES MUST BE INCLUDED IN YOUR OUTPUT:
Enter month, day, year separated by spaces 6 30 2017
6 30 2017 is a valid date
Enter month, day, year separated by spaces 6 31 2017
month 6 can not have more than 30 days
Enter month, day, year separated by spaces -3 12 2019
-3 is not a valid month
Enter month, day, year separated by spaces 2 29 2000
2 29 2000 is a valid date
Enter month, day, year separated by spaces 2 30 2000
month 2 can not have 30 days
Enter month, day, year separated by spaces 2 -12 2019
month 2 can not have -12 days
Enter month, day, year separated by spaces 2 29 2001
2001 is not a leap year, 29 is invalid
Enter month, day, year separated by spaces 6 32 -109
year can not be negative
Enter month, day, year separated by spaces 6 32 2017
month 6 can not have more than 30 days
There are many ways to approach this problem. I recommend coding the input statements and steps 1-3 first and making sure they work properly.
Then move on to step 4.
Thank you!!!
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