Hi everyone, I have an assignees that I've been working on and I'm stuck on the last function.

use the function void Increment(int numDays = 1)

This function should move the date forward by the number of calendar days given in the argument. Default value on the parameter is 1 day. Examples:

Date d1(10, 31, 1998); // Oct 31, 1998
Date d2(6, 29, 1950); // June 29, 1950

d1.Increment(); // d1 is now Nov 1, 1998
d2.Increment(5); // d2 is now July 4, 1950

I don not understand how to do this.

void Date::Increment(int numDays = 1)
{
I'm stuck, I know how to tell the function to increment, by the ++ operator but i get confuse when I have to get the function to increment the last day of the month to the the fist, or to end at the last date of that month for example. Oct 31 to Nov 1, or June 29 to July 4. I can do July 5 to July 8 but the changing months confuse me
}

What results are you getting with the code you have currently written, do you have compiler errors? Or does it compile and behave undesirably?

What results are you getting with the code you have currently written, do you have compiler errors? Or does it compile and behave undesirably?

I do not have compiling error, my problem is that I can only get the date to increment within that month, I can not get it to increment from month to month. For example September 30 increment by 5 is suppose to be Oct. 5 but that't not displaying at all

can you post your full code per chance?
I don't know what all your method bodies do or what you objects look like

this really sounds like you want to just do incMonth = month + 5, print incMonth;
that would preserve the month value.

can you post your full code per chance?
I don't know what all your method bodies do or what you objects look like

void Date::Increment(int incre)
{
    int newDay, day2;
    if ((month == 1)||(month == 3)||(month == 5)||(month == 7)||(month == 8)||(month == 10)||(month == 12))
    {
        day2 = day + incre;
        if (day2 > 31)
            day = day2;
        else 
        {
            newDay = day2 - day;
            month++;
            day = newDay;
        }
    }
}

for months that have 31 days

I'm assuming 'month' is an integer? Where is that defined?

I'm assuming 'month' is an integer? Where is that defined?

Thank you all so much for you help, I found out my mistake

I'm glad I could help you, I kindly invite you to close this thread as solved at the bottom if you don't feel you have any other concerns.

Happy Hacking gina_cs!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.