I am trying to get advanceDate to change the date of an "appointment" object it just adds 1 to the day integer.
when I call the print function inside the advanceDate function. It prints the modified value I am looking for. But after it returns the object and I call print again inside my Main, the original value is back? I'm sure this is something simple I am overlooking or forgetting any ideas?

void main()
{
    appointment newApp(123,"Andrew",7,12,1987);
    newApp.print(cout,1);
    advanceDate(newApp,5);
    newApp.print(cout,1);
    system("pause");
    return;
}
appointment advanceDate( const appointment & e, int numberOfDays)
{
    appointment newApp2(e);
    for(int x = 0; x < numberOfDays; x++)
    {
        newApp2.incrementDate();
    }
    newApp2.print(cout,1);

    return newApp2;

}

The function advanceDate does not touch the appointment object you are passing into it. You are making a copy named newApp2 (like this - appointment newApp2(e);), altering the copy, outputting something from the copy, and then returning the copy (which is promptly thrown away). If you want to change the appointment object you are passing by reference to the function, don't make a copy of it. Just work directly on it.

appointment advanceDate(appointment & e, int numberOfDays)
{
    for(int x = 0; x < numberOfDays; x++)
    {
        e.incrementDate();
    }
    e.print(cout,1);
}
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.