A record and a
struct are the same thing. A structure is just a collection of other data, just like you have.
1 2 3 4 5
|
struct printDate {
int day;
int month;
int year;
};
|
Here you have three data stored under one name. (With a type of "printDate").
Your function and variable names need a little help. For example, "getDate" would be better named something like "parseDate" or "intToDate" or the like. Likewise, your "printDate" structure might be better named just "Date".
Don't forget to
return things from functions that return a value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
struct Date {
int day;
int month;
int year;
};
Date intToDate( int date )
{
Date result;
result.day = ...;
result.month = ...;
result.year = ...;
return result;
}
|
For the "getDate"/"intToDate" function, your math needs a little help. Remember that "%" is the
remainder operator, returning the remainder of an integer division. For example,
1 2 3 4 5 6 7 8 9
|
9 / 1 = 9; 9 % 1 = 0
9 / 2 = 4; 9 % 2 = 1
9 / 3 = 3; 9 % 3 = 0
9 / 4 = 2; 9 % 4 = 1
9 / 5 = 1; 9 % 5 = 4
9 / 6 = 1; 9 % 6 = 3
9 / 7 = 1; 9 % 7 = 2
9 / 8 = 1; 9 % 8 = 1
9 / 9 = 1; 9 % 9 = 0
|
The way you currently have it coded, you are extracting the
same number as different things.
That said, you probably want to write a function to read the birthdate as three separate integers that you put directly into the "Date" struct.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
Date askBirthday()
{
Date result;
cout << "year: " << flush;
cin >> result.year;
cout << "month (1-12): " << flush;
cin >> result.month;
cout << "day (1-31): " << flush;
cin >> result.day;
return result;
}
...
int main()
{
Date yourBirthday;
Date anotherBirthday;
cout << "Please enter your birthday\n";
yourBirthday = askBirthday();
...
|
Finally, when comparing dates, compare the most significant numbers first. The year is more important than the month, and the month is more important than the day.
Hope this helps.
[edit] Wow, after all that someone did the OP's homework for him before I could hit the Submit button. Way to go!