dimanche 1 mars 2015

c++ how to modify a struct using a call from another function


I'm trying to understand how to write a function that can modify a struct. I want to add a day to my struct Date. The addOneDay function below doesn't work.


My goal is to addOneDay to my birthday, using a function. How do I manipulate the data in the struct to get addOneDay to work?



#include <iostream>

using namespace std;

struct Date
{
int year;
int month;
int day;
};


Date addOneDay(const Date& date);

Date addOneDay(const Date& date)
{
Date rdate = date.day+1; /* <- this doesn't work */
return rdate;
};

void assignValues(Date& myBirthday)
{
myBirthday.day = 27;
myBirthday.month = 1;
myBirthday.year = 1962;
}

main()
{
Date x;
assignValues(x);

cout << x.month << "/" << x.day << "/" << x.year << endl;

//addOneDay(x)
};



Aucun commentaire:

Enregistrer un commentaire