Adding days to entered date, simple.

Hi

Im completely stuck on this, I need to create an algorithm that takes a day/month and number of days that you want to add and returns the date. Ive been told to use a function named nextDay. i can also ignore leap years and assume feb is always 28 days. ive also been given the hint to use call by reference.

Not sure how to incorporate the number of days in each month. any help would be appreciated, most of the other stuff i found is more complicated.
You need an array of exact 12 entries that contains the days per month.

The given month you can use as an index within this array. if day + add_days is less than the days in that array, everything is fine, the month passed is the result month. Otherwise you must substract the days in the array until day + add_days is less (sounds like a recusion)

You need to take care that the index is within the array (normaly january = 1 so index = month - 1)
Im not sure what you mean by using the month as an index?
i got to here:

#include <iostream>

using namespace std;
int nextDay(int month, int day);
int main ()
{
int month, day, add_days;

int days [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

not sure what to do here after this...
no the array belongs in the nextDay() function.

this task is slightly advance. You need to know about loops, if clause, passing prarameter...

Im not sure what you mean by using the month as an index?
It means that you can do so:

int days_per_month = days[month];


What does the result of nextDay() is supposed to mean? The day in the month or year? When it's the day in month you don't know which month you have after adding. Consider feb 22 + 10 days
Last edited on
Topic archived. No new replies allowed.