Pseudo Code:
- Initialize Variables:
- Set
Year
to a given value. - Set
Month
to a given value. - Check for Valid Year:
- If
Year
is between 2000 and 2025, proceed. - Else, print an error message.
- Determine Days in the Month:
- Use
if
,else if
, andelse
statements to assign the correct number of days to each month. - February needs special handling:
- If
Year
is a leap year (divisible by 4
but not100
, exceptdivisible by 400
), set February to 29 days. - Otherwise, set February to 28 days.
- Print the Result.
# Define the year and month
Year <- 2001
Month <- "May"
# Check if the year is within the valid range
if (Year >= 2000 & Year <= 2025) {
# Determine number of days based on the month
if (Month == "January" | Month == "March" | Month == "May" |
Month == "July" | Month == "August" | Month == "October" | Month == "December") {
Days <- 31
} else if (Month == "April" | Month == "June" | Month == "September" | Month == "November") {
Days <- 30
} else if (Month == "February") {
# Check if it's a leap year
if ((Year %% 4 == 0 & Year %% 100 != 0) | (Year %% 400 == 0)) {
Days <- 29
} else {
Days <- 28
}
} else {
Days <- NA # Invalid month input
print("Error: Invalid month name. Please enter a valid month.")
}
# Print result if month was valid
if (!is.na(Days)) {
print(paste(Month, Year, "has", Days, "days."))
}
} else {
print("Error: Year out of range. Please enter a year between 2000 and 2025.")
}