need an algorithm

Hello. I want to write a program, in which user can cin days month and year, and


n number of days. The program should output a new date, which will be n days from the entered date.

Could anyone please help me. I know that I have to store months in array and do it with maybe while loops, but I cannot go any further...

any ideas anybody?

note that I do not want to use any c++ library or algorithm functions, I want to write it myself. I mean I do not need any helpful algorithms written in libraries.

Thank you very much for attention. :)
have a go yourself and when you have specific questions ask away.

for user IO:
http://www.cplusplus.com/doc/tutorial/basic_io/

and arrays:
http://www.cplusplus.com/doc/tutorial/arrays/

Last edited on
The most straightforward way is to make a function that converts a date (year, month, day) into the day of the year (often called, erroneously, the Julian day). Convert both dates to their day-of-the-year values, and find the difference between them.

Keep in mind that if the first date's value is greater than the second's then you must find the number of days between the first and December 31.

1
2
3
4
if (day_of_year1 < day_of_year2)
  days_difference = day_of_year2 - day_of_year1;
else
  days_difference = calc_day_of_year( year1, 12, 31 ) - day_of_year1 + day_of_year2;

Good luck!
Topic archived. No new replies allowed.