Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem #3: Birthday Comparison Note: This program does not require any form of loop. You are writing a program which compares two birthdays and reports
Problem #3: Birthday Comparison Note: This program does not require any form of loop. You are writing a program which compares two birthdays and reports which person is older - or if they are the same age. While simple for a human, this requires quite a few steps for a computer, Follow the following format: Create boolean variables to store whether Date A and Date B are valid. Set them to True; the check later on will detemine if they are false. Prompt the user to enter Date A followed by Date B. Each date has a month, day, and year, and each of these values should be stored in different variables (so month_A, day_A, year_A, and so on). Check to see if the dates are valid - Check date A, then check date B. Depending on the month, a date can have a specific range of dates. April, June, September, and November have days 1-30, Feburary can have days 1-29 (Assume a leap date is possible to input), and the other months can have days 1-31.) If the date is invalid, set the boolean value for that date to false, If both dates are valid: Create boolean values to store if the dates are the same and if date A is older than date B. Assume the former is false and the latter is true; The checks will determine if the former is true and the latter is false. . Compare the dates. Check in the order of year, month, and then day, using nested decision structures to minimize your checks (for example, if year_A is before year_B, then you do not need to check for month and day). If the year, month and day are all the same, then both dates are the same, then the boolean for the dates being the same is true. Otherwise, check to see if Person A is older than Person B, setting the "is Person A older" variable appropriately. . If the users have the same age, tell the user, "Person A and Person B have the same age!" Else, if Person A is older than Person B, tell the user, "Person A is older!" Else, tell the user, "Person B is older!" . Otherwise, tell the user "You entered an invalid date. Try again!" Here are a few sample runnings of the program, with user input bolded: Run #1 Enter the birth month of Person A: 08 Enter the birth day of Person A: 23 Enter the birth year of Person A: 1994 Enter the birth month of Person B: 09 Enter the birth day of Person B: 13 Enter the birth year of Person B: 1994 Person A is older! Run #2 Enter the birth month of Person A: 7 Enter the birth day of Person A: 15 Enter the birth year of Person A: 1996 Enter the birth month of Person B: 7 Enter the birth day of Person B: 10 Enter the birth year of Person B: 1996 Person B is older! Run #3 Enter the birth month of Person A: 9 Enter the birth day of Person A: 18 Enter the birth year of Person A: 1995 Enter the birth month of Person B: 9 Enter the birth day of Person B: 18 Enter the birth year of Person B: 1995 Person A and Person B have the same age! Run #4 Enter the birth month of Person A: 99 Enter the birth day of Person A: 12 Enter the birth year of Person A: 1356 Enter the birth month of Person B: 12 Enter the birth day of Person B: 67 Enter the birth year of Person B: 1495 You entered an invalid date. Try again
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