I have a header file and a cpp file that i cannot get to compile. The exercise in the book states i need to make a static char of the months. But for some reason i am having trouble initializing the static char[12][25] array for the 12 months. Getting error codes stating syntax error. Any help would be much helpful....Here is my header file and my main file...
#ifndef DAYOFYEAR_H
#define DAYOFYEAR_H
#include <iostream>
using namespace std;
class DayOfYear
{
private:
static char month[12][25];
int dayOfYear;
public:
DayOfYear()
{
dayOfYear = 0;
month[12][25] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
}
void setDayOfYear(int doy)
{ dayOfYear = doy; }
void printDayOfYear()
{
cout << "Day " << dayOfYear << " would be ";
if(dayOfYear < 32)
cout << month[0] << " " << dayOfYear << endl; //Jan
else if(dayOfYear < 60)
cout << month[1] << " " << (dayOfYear) % 31 << endl; //Feb
else if(dayOfYear < 91)
cout << month[2] << " " << (dayOfYear - 27) % 28 << endl; //March
else if(dayOfYear < 121)
cout << month[3] << " " << (dayOfYear - 57) % 31 << endl; //April
else if(dayOfYear < 152)
cout << month[4] << " " << (dayOfYear - 88) % 30 << endl; //May
else if(dayOfYear < 182)
cout << month[5] << " " << (dayOfYear - 118) % 31 << endl; //June
else if(dayOfYear < 213)
cout << month[6] << " " << (dayOfYear - 149) % 30 << endl; //July
else if(dayOfYear < 244)
cout << month[7] << " " << (dayOfYear - 180) % 31 << endl; //August
else if(dayOfYear < 274)
cout << month[8] << " " << (dayOfYear - 212) % 31 << endl; //Sept
else if(dayOfYear < 305)
cout << month[9] << " " << (dayOfYear - 242) % 30 << endl; //Oct
else if(dayOfYear < 335)
cout << month[10] << " " << (dayOfYear - 273) % 31 << endl; //Nov
else if(dayOfYear < 366)
cout << month[11] << " " << (dayOfYear - 304) % 30 << endl; //Dec
}
};
#endif
#include <iostream>
#include "DayOfYear.h"
using namespace std;
int main()
{
DayOfYear doy;
doy.setDayOfYear(288);
doy.printDayOfYear();
return 0;
}