Jul 21, 2009 at 1:23am UTC
I already searched in google on how to fix this problem, but I still get the error.
I was using "using namespace std;" at first. I changed that for the following, because it seemed that people were getting results. Nonetheless, that didn't work for me.
This is the code:
ETA: I get the error in line 20.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
//Class Definition
class DayOfYear {
private :
static string month;
int day;
public :
//Constructor
DayOfYear(int a) { day = a;}
void print();
}//end of class
string DayOfYear::month;
//Function Member Definitions
////****************************************************
void DayOfYear::print()
{
if (day >= 1 || day <= 31)
{
month = "January" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=32 || day <= 59)
{
month = "February" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=60 || day <= 90)
{
month = "March" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=91 || day <= 120)
{
month = "April" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=121 || day <= 151)
{
month = "May" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=152 || day <= 181)
{
month = "June" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=182 || day <= 212)
{
month = "July" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=213 || day <= 243)
{
month = "August" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=244 || day <= 273)
{
month = "September" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=274 || day <= 304)
{
month = "October" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=305 || day <= 334)
{
month = "November" ;
cout<<month<<" " <<day;
cout<<endl;
}
else if (day >=335 || day <= 365)
{
month = "December" ;
cout<<month<<" " <<day;
cout<<endl;
}
}//end of print()
//*************************MAIN FUNCTION****************************************
int main ()
{
string DayOfYear::month = " " ;
int dDay = 0;
cout<<"This program helps you find a day of the year." <<endl;
cout<<"Please enter the number of the year that you want me to show:" ;
cin>>dDay;
cout<<endl;
//Object Creation
DayOfClass object1(dDay);
object1.print();
system("pause" );
return 0;
}//end of main function
Last edited on Jul 21, 2009 at 1:24am UTC
Jul 21, 2009 at 1:47am UTC
if you want to use the keyword using
using namespace std;
a better idea would be to do the following
std::string myString;
Also I have heard, but am not entirely certain as to why, but don't use system for pausing, rather use
std::cin>>aString;
Last edited on Jul 21, 2009 at 1:49am UTC
Jul 21, 2009 at 1:59am UTC
for statics I thought you had to include the type of the variable?
Jul 21, 2009 at 2:37am UTC
Yeah, but he is already declaring it in the class what type it is...(I don't use statics much though so I could be wrong).
Jul 21, 2009 at 3:40am UTC
The reason you are getting the error on line 20 is that there is no semicolon terminating your class declaration ending on line 18.
Next, you are trying to do something to a private member variable in your main function on line 119. Don't do that. If you want to initialize it to something (like " " ) then do that on line 20.
Finally, on line 130 you mistyped "DayOfYear " as "DayOfClass ".
Oh yeah, if you want to use system () -- which I don't recommend; see the link that firedraco posted for you -- then you must also #include <cstdlib>.
Your using statements are fine.
Hope this helps.
Jul 21, 2009 at 1:48pm UTC
Thank you everybody.
I went to sleep early yesterday as I was very tired. Now, I can see the mistakes clearly.
Have a good day!