Hi there. I am getting the errors below when I am trying to compile this code using DEV C++.
[Linker error] undefined reference to 'CheckLeapYear'(int)
[Linker error] undefined reference to 'CalcDayNumOfYear'(int)
[Linker error] undefined reference to 'CheckLeapYear'(int)
Id returned 1 exit status
Please help. Below I have included my coding
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
int GetDate (int&, int&, int&); //function prototype
int CheckLeapYear(int);
int CalcDayNumOfYear(int, int, int&);
int main()
{
int day;
int month;
int year;
int dayOfPreviousMonth=0;
int dayNumOfYear;
GetDate (day, month, year);
CheckLeapYear(year);
CalcDayNumOfYear(dayOfPreviousMonth, day, dayNumOfYear);
cout <<"It is day" <<dayNumOfYear<< "of the year."<<endl;
}
int GetDate(int& day, int& month, int& year)
{
cout<<"Enter a date: (dd/mm/yyyy)";
cin>>day>>month>>year;
if (day < 1 || day > 31)
{
cout<<"Day entered is invalid"<<endl;
}
if (month < 1 || month > 12)
{
cout<<"Month entered is invalid"<<endl;
}
int CheckLeapYear(year);
{
if(((year % 100 == 0)&&(year % 400 == 0)) || ((year % 100 != 0) && (year % 4 == 0)))
return true;
else
return false;
}
}
int CalcDayOfYear(int dayNumber, int month, int year, int dayOfPreviousMonth, int day, int& dayNumOfYear)
{
if (year != CheckLeapYear (year))
{
switch (month)
{
case 1: dayNumber = day;
break;
case 2: dayNumber = 31+day;
break;
case 3: dayNumber = 59+day;
break;
case 4: dayNumber = 90+day;
break;
case 5: dayNumber = 120+day;
break;
case 6: dayNumber = 151+day;
break;
case 7: dayNumber = 181+day;
break;
case 8: dayNumber = 212+day;
break;
case 9: dayNumber = 243+day;
break;
case 10: dayNumber = 273+day;
break;
case 11: dayNumber = 304+day;
break;
case 12: dayNumber = 334+day;
break;
default:;
}
}
else
switch (month)
{
case 1: dayNumber = day;
break;
case 2: dayNumber = 31+day;
break;
case 3: dayNumber = 60+day;
break;
case 4: dayNumber = 91+day;
break;
case 5: dayNumber = 121+day;
break;
case 6: dayNumber = 152+day;
break;
case 7: dayNumber = 182+day;
break;
case 8: dayNumber = 213+day;
break;
case 9: dayNumber = 244+day;
break;
case 10: dayNumber = 274+day;
break;
case 11: dayNumber = 305+day;
break;
case 12: dayNumber = 335+day;
break;
default:;
}
}