Invoking a function?

I am having an issue invoking a leapYr function whereby I am to determine if the year entered is a leap year and what day number the date entered falls on. I am using C++ Dev compiler.

Anytime I think I am invoking the leapYr function within the dayNumber function I get an error that states I cannot use either of the 2 as functions. I am writing them as I have done other assignments and they worked just fine so I am not sure what I am doing wrong. Can anyone "guide" me to the area that is inaccurate so I can pinpoint it on my own? thanks

#include <iostream>

using namespace std;

void instruct()
{
//Enter a date as all integers to determine what number day of the year it is and i
cout << "Enter a date with a format x x xxxx as all integers to determine " << endl;
cout << "what day of the year it is as well as if the year is a leap year. " << endl << endl;
}
//end instruct

bool LeapYr(int Y,int D,int totalDays)
{
if ((Y%4==0) || (Y%100!= 0) && (Y%400 == 0))
{
return D + 1;
}
else
{
return false;
}
}

int dayNumber (int M, int D, int Y, int totalDays)
{
if (M == 1) totalDays = 0;
else;
if (M == 2) totalDays = 0+31;
else;
if (M == 3) totalDays = 0+31+28;
else;
if (M == 4) totalDays = 0+31+28+31;
else;
if (M == 5) totalDays = 0+31+28+31+30;
else;
if (M == 6) totalDays = 0+31+28+31+30+31;
else;
if (M == 7) totalDays = 0+31+28+31+30+31+30;
else;
if (M == 8) totalDays = 0+31+28+31+30+31+30+31;
else;
if (M == 9) totalDays = 0+31+28+31+30+31+30+31+30;
else;
if (M == 10) totalDays = 0+31+28+31+30+31+30+31+30+31;
else;
if (M == 11) totalDays = 0+31+28+31+30+31+30+31+30+31+30;
else;
if (M == 12) totalDays = 0+31+28+31+30+31+30+31+30+31+30+31;




}
int main()
{
int date;
int Year;
int Month;
int Day;
int Mo;
int checkLeapYr;
int dayNumber;
int totalDays;
int dayNum;
instruct();

//Enter a month as an integer from 1 - 12
cout << "Enter a Month as an integer: "; cin >> Month;
cout << endl;

//Enter a number, 1-31, to represent a day
cout << "Enter a number, 1 - 31, to represent the day: "; cin >> Day;
cout << endl;

//Enter a year as a 4 digit integer
cout << "Enter a year as a 4 digit integer: "; cin >> Year;
cout << endl;

//Calculate
totalDays = LeapYr(Month, Day, Year, totalDays);
dayNumber = LeapYr(Year, Day, totalDays);


//Display the day number for the input date
cout << "The day number for " << Month << "/" << Day << "/" << Year << " is " << totalDays; cout << endl << endl;


Last edited on
totalDays = LeapYr(Month, Day, Year, totalDays);
is a wrong number of arguments.
did you mean to use dayNumber here instead?

by the way, when you post code, use [code] tags
Dev-C++ is bad blah blah blah upgrade to save your sanity: http://wxdsgn.sourceforge.net/?q=node/4
Now that that's out of the way, Your "LeapYr(...)" function returns a bool which you are trying to assign to integer datatypes "totalDays" and "dayNumber". Also this program isn't so complex that you've already run out of names, please change the name of your "dayNumber" variable inside of main(...) to something that doesn't match your "dayNumber" function.
Last edited on
originally I had [totaldays=LeapYr(Month, Day, Year, dayNumber)] but I was getting an error:

too many arguments to function `bool LeapYr(int, int, int)'

which is why I changed it back to .....(Month,Day,Year,totalDays)
That's still too many arguments. You have space for three arguments allocated, if you need more then just change the function so that it excepts more.
Are you aware that you have this:
1
2
3
//Calculate
totalDays = LeapYr(Month, Day, Year, totalDays);
dayNumber = LeapYr(Year, Day, totalDays); 


Shouldn't it be:
1
2
3
//Calculate
totalDays = LeapYr( Month, Day, Year, totalDays );
dayNumber = dayNumber( Year, Day, totalDays ); 
Last edited on
Thank you everyone. I figured it out.
Topic archived. No new replies allowed.