Ok, there are a couple of problems here, that you should target. First, to fix your code, the error is very simple: there isn't anywhere in your code in which a variable named start
was declared/defined. So, the compiler is asking you what start
is. You are trying, I assume, to initialize the values of the members of d, that you passed in the function initializeDate
, and all you have to do is just replace every occurence of the word start
with d
, and you'll get:
void initializeDate(Date &d)
{
cout<<"Please enter the month"<<endl;
cin>> d.month;
cout<<"Please enter the day"<<endl;
cin>> d.day;
cout<<"Please enter the year"<<endl;
cin>> d.year;
string dummy;
getline(cin, dummy);
}
Now, although this works, it's not the best way to initialize the date. Since Date
is a struct
, you can initialize its members using a constructor method. This is achieved by writing it like this:
struct Date{
int day, month, year;
Date(int, int, int);
};
Date:: Date(int day, int month, int year){
this->day = day;
this->month = month;
this->year = year;
}
int main(){
Date today(11, 3, 2013);
cout << "today, the date is " << today.day << "-" << today.month << "-" << today.year << endl;
return 0;
}