Checks for months with 30 maximum days maxdays 30 else maxdays 31 return

Checks for months with 30 maximum days maxdays 30

This preview shows page 1 - 2 out of 2 pages.

Checks for months with 30 maximum days max_days = 30; else max_days = 31; return max_days; } // Function to update date by specified number of days. struct date update_date(struct date d, int days) { d.day += days; // Adds days to date's day int max_days = max_days_in_month(d); // If days exceed maximum number of days in a month then it updates the day and increments the month if(d.day > max_days) { d.day = d.day - max_days; d.month++; } // If month exceeds 12 then it updates the month and increments the year
Image of page 1
if(d.month > 12) { d.month = d.month - 12; d.year++; } return d; } int main() { int days = 7; bool valid = false; struct date d; // Structure variable to hold input date struct date new_date; // Structure variable to hold updated date while(!valid) // Prompt for input until valid date is entered. { printf("Please enter date in the format mm/dd/yyyy.\n"); scanf("%d/%d/%d",&d.month, &d.day, &d.year); /* Checks if the date is valid or not. Date is valid if year is in between 0 to 9999, month in between 1 to 12 and day in the range of maximum days in the month. */ if(d.year >= 0 && d.year <= 9999 && d.day <= max_days_in_month(d) && d.day >0 && d.month <=12 && d.month >=1) { valid = true; } else { printf("\nInvalid date!\n"); } } printf("\nEntered date is: %02d/%02d/%04d\n", d.month, d.day, d.year); // Updates the date by calling custom function with date parameter. new_date = update_date(d,days); printf("\nDate after 7 days is: %02d/%02d/%04d\n", new_date.month, new_date.day, new_date.year); return 0; }
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

  • Spring '13

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes