0

Hi guys, any help appreciated here. This is what I have so far.

int getDaysBetweenDates(int day, int month, int year, int day2, int month2, int year2)
{
	if(isFirstDateGreaterThanSecond(int month1, int day1, int year1, int month2, int day2, int year2))
		{
		return getDaysBetweenDates(month2, day2, year2, month1, day1, year1)
		}
	else if(year1 == year2)
		{
		return getDayNumber(month2, day2, year2) - getDayNumber(month1, day1, year1);
		}
	else getDayNumber(month2, day2, year2) + getDayNumber(month1, day1, year1, 12, 31, year2 - 1);

}

int getDayNumber(int month1, int day 1, int year1, int month2, int day2, int year2)
{

		int a, y, m, yearBefore, daynumber;
	int daynumber = 0;
	int julianDay = 0;	

	cin>>month1>>day1>>year1;
	
	for(yearBefore=year1; yearBefore >= (year1-1); yearBefore--)
	{
	a = (14 - month1) / 12;
	y = yearBefore + 4800 - a;
	m = month + 12 * a - 3;
	
	julianDay = day + (153 * m + 2) / 5 + y *  365 + y / 4 - y/100 + y/400 - 32045;
	
		if(day1==0)
		{
		daynumber1 += julianDay;
		}
		else
		{
		daynumber1 -= julianDay;
		}
			
	day = 31;
	month = 12;
	}
	return daynumber1;
	


	
}

These are just parts of a much bigger program. My question is.. I need to know how to pass the variables to my getDayNumber function. But here is the problem I have.

If I do a call to getdaynumber like, "getdaynumber(month2, day2, year2)" how do I get it to return the value for this date? Instead of month1, day1, year1?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by siddhant3s
0

There are several option when you write functions that return multiple values:
1. Using references: You could have few parameters that will be passed as references and use them to store the output

void split_decimal(double input, int& integer_part, double& fraction_part)
{
   integer_part=static_cast<int>(input);//convert input to integer
                                                                    // and store in integer_part
   fraction_part=input-integer_part;
}
//usage:
double val=1.254;
double frac;
int integer;
split_decimal(val,integer,frac);
//now integer=1 and frac=0.254

2.To return an array (or vector): if all the output values are of same type, you may return a array of all those values. But I do not suggest this method as it is clumsy.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.