C++ Question

This is a discussion on C++ Question within the C++ Programming forums, part of the General Programming Boards category; Can anyone give pointers on how to write a funtion that would return the later of any two dates passed ...

what is a 'date' specificially? what have you tried? where are you stuck? please post code. if you havent attempted this then post as much C++ code mixed with pseudo-code (english version of programming code and syntax) as you can and then we have a place to start.

so now we must implement this function and add code in its body so it will do what you want. as i have said in an earlier post, write pseudocode (simply english sentences, lets say), to model what you are trying to do. ill give an example.

i hope i get somewhere with that, sorry if its a dumb example which doesnt make sense.

now, having your code:

Code:

Date& larger(Date date1, Date date2)
{
// ....
}

simply write english terms and phrases to layout what you want to do where the // .... is. tip: see post 2. if you dont know how to work with structures search somewhere for a c++ tutorial on it, they really arent hard.

I can see some idea behind this. It looks like an attempt to add up year, month and day, so you get a comparable value.

If I had to come up with something like that just to compare if one date is larger than the other (but don't need to know by how much), I'd try something like that: x = day+month*31+year*31*12
This of course assumes all months are 31 days for simplicity, making each year 372 days long. This makes the dates comparable, but if I needed something finer, I'd probably study date and time functions.

(If the world didn't end before, eventually at some point a year would be 372 days long. I wish it would happen sooner

You've got the right idea here. You have to change the gregorian date format of mm/dd/yyyy to an integer (julian day) so that you can do your calculations. Once you get your answer, you have to change it back to the gregorian date format. The formula will take into account leap years and various days in a month. I would think that you're instructor would give you the algorithm or code for this. You want Volume 6, No. 8, p. 444 I don't know if they charge for a student membership. Once you get the format changed, the rest is much easier.