Im just having a fiddle with some code from a book of mine,
Basically There is a structure like:
struct date
{ int day;
char string[8];
int year;
};
The book says the user has to input 2 birthdays and a function, called check has to see if they're the same.
Now have had a go with doing something like:
struct date birthdayone
cin << birthday1.day << birthday1.string etc
and the same with birthdaytwo.
Im just having problems trying to put all my inputed data for birthday1 and birthday2 into a function that checks to see if they're equal. I could put all six inputs but that seems sloppy
opinions anyone?
>> char string[8];
will cause trouble, since 'string' also is an STL class - I'd recommend using
struct date
{
int day;
char month[8];
int year;
};
As for your Q, I'd use helper functions, e.g.
void ReadDate ( istream& str, date& r) {
str >> r.day >> r.month>> r.year;
}
bool IsSameDate ( date& r1, date& r2) {
if ( r1.day != r2.day) return false;
if ( r1.year != r2.year) return false;
if ( strcmp(r1.month,r2.month))
return true;
}
//.....
date d1;
date d2;
ReadDate ( cin, d1);
ReadDate ( cin, d2);
bool bTheSame = IsSameDate(d1,d2);