// JP opened flex table

Click to See Complete Forum and Search --> : need help quick!


voltagejim3000
March 3rd, 2008, 12:56 PM
I have a program that is almost done, but I have 2 errors that I cannot figure out what they are. I have been looking for an hour, and can come up with no solution! The program I am doing is supposed to take the users inputed month and year, and output the days in the month and whether it is a leap year or not. Here is the code:



#include<iostream>
using namespace std;
bool isleap(int);
int daysinmonth(int);
void main()
{
int year;
int month;
cout << "Enter the month: ";
cin >> month;
cout << "Enter the year: ";
cin >> year;

while (!cin.eof())
{
if (isleap(year))
{
cout << year << " Leap year" << endl;
cout << "There are " << daysinmonth << " days in the month of " << month << " during leap year" << endl;
}

else{
cout << year << " Not a leap year" << endl;
cout << "There are " << daysinmonth << " days in the month of the month of " << month << endl;

}
cout << "Enter the year: ";
cin >> year;
cout << "Enter the month: ";
cin >> month;
}
}
bool isleap(int y)
{
if ((y%4 == 0 && y%100 != 0) || (y%400 == 0))
return true;
else
return false;
}
int daysinmonth(int year, int month)
{
if (month == 1 || month == 3 ||month == 5 ||month == 7 || month == 8 || month == 10 || month == 12){
return 31;
}
else if(month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}
else if (isleap(year) && month == 2){
return 29;
}
else
return 28;

}




The errors are :

1>month.obj : error LNK2019: unresolved external symbol "int __cdecl daysinmonth(int)" (?daysinmonth@@YAHH@Z) referenced in function _main
1>E:\month\Debug\month.exe : fatal error LNK1120: 1 unresolved externals

darwen
March 3rd, 2008, 04:10 PM
Your initial declaration of daysinmonth doesn't match its implementation i.e.


// declaration takes 1 int
int daysinmonth(int);

// implementation takes 2 ints
int daysinmonth(int year, int month)
{
//...
}


Either change the declaration to


int daysinmonth(int year, int month);


or move the implementation of daysinmonth to before it's called.

You'll have to change where it's called in main too -


cout << "There are " << daysinmonth << //...


to


cout << "There are " << daysinmonth(year, month) << //...


Darwen.

PS In future USE CODE TAGS !!. See the link in my signature.

//JP added flex table