Date Programm

I working on this assignment, but I got a huge load of errors, I don't know where I messed up. I will put what I have to do and will specify what I did in the code. This is a multiple file program.

1) Given the source code and the pseudo-code
supplied complete the following functions:

- static bool isLeapDay(int day, int month, int year);
This predicate will return true if the date represented by the arguments is
a leapday, false otherwise.

- void addDay(bool forward);
This function will change a date by one day: forward if the argument is true
and backward if false.

- static int maxDay(int month, int year);
This function will return the maximum day for the month and the year of the
arguments

- void addYears(int years);
This function will add years to the date object. If the argument is
negative, the modified date is before the function is called.

- void addMonths(int months);
This function will add months to the date object. If the argument is
negative, the modified date is before the function is called.

- void addDays(int days);
This function will add days to the date object. If the argument is
negative, the modified date is before the function is called.

The code in test.cpp will test to see if your work is correct. Compiling and
running the existing program will cause incorrect data to be displayed.

NOTE -- VERY IMPORTANT: Only modify date.cpp and only the functions indicated.

Now the code for the files

test.cpp
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
#include <iostream>
#include <string>

#include "date.h"

int main()
{
    std::cout << "Testing the explicit ctor:" <<std::endl;  
    Date then(29, 2, 2012);
    std::cout << "Leap day, this year: " << then.toString() << std::endl;
    then.addYears(3);
    std::cout << "Adding three years to it: " << then.toString() << std::endl << std::endl;

    std::cout << "Testing the default ctor:" <<std::endl;  
    Date now;
    std::cout << "The date right now: " << now.toString() << std::endl;
    now.addYears(-10);
    std::cout << "The Date ten years ago: " << now.toString() << std::endl << std::endl;


    std::cout << "Creating a date object:" <<std::endl;  
    Date dateTest1(31, 8, 2006);
    std::cout << "The date: " << dateTest1.toString() << std::endl;
    dateTest1.addMonths(10);
    std::cout << "The Date ten months later: " << dateTest1.toString() << std::endl;
    dateTest1.addMonths(-19);
    std::cout << "The Date nineteen months before: " << dateTest1.toString() << std::endl << std::endl;


    std::cout << "Creating a date object, St. Patrick's day, long ago:" <<std::endl;  
    Date dateTest2(17, 3, 1066);
    std::cout << "The date: " << dateTest2.toString() << std::endl;
    dateTest2.addDays(7);
    std::cout << "Adding a week: " << dateTest2.toString() << std::endl;
    dateTest2.addDays(364);
    std::cout << "Adding a year less a day: " << dateTest2.toString() << std::endl;
    dateTest2.addDays(-500);
    std::cout << "Subracting five hundred Days: " << dateTest2.toString() << std::endl << std::endl;

    
    return 0;
}


date.cpp

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include <iostream>
#include <sstream>
#include <ctime>
#include "date.h"

const std::string Date::MONTH_STRINGS[] = 
{
    "", //one based indexing
    "January",
    "February",
    "March",
    "April",
    "May", 
    "June",
    "July",
    "August",
    "Septenber",
    "October",
    "November",
    "December"
};

const int Date::DAYS_PER_MONTH[] =
{
    0, //one based indexing
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
    
};      



Date::Date(int day, int month, int year) : _year(year), _month(month), _day(day)
{
    isValid();
}

Date::Date()
{
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );
    _year = now -> tm_year + 1900;
    _month = now -> tm_mon + 1;
    _day = now -> tm_mday;
}

std::string Date::toString() const
{
    if(isValid() == false)
    {
        return std::string();
    }
    std::stringstream ss;
    ss  << MONTH_STRINGS[_month] << " " << _day << ", " <<  _year;
    return ss.str();            
}    

bool Date::isValid() const
{
    if(_month < MIN_MONTH || _month > MAX_MONTH)
    {
        std::cerr << "Invalid date " << std::endl;
        return false;
    }
    int daysThisMonth = maxDay(_month, _year);
     
    if(_day < MIN_DAY || _day > daysThisMonth)
    {
        std::cerr << "Invalid date " << std::endl;            
        return false;
        
    }
    
    
    return true;
}

bool Date::isLeapYear(int year)
{
    if(!(year % 4))
    {
        if(!(year % 100))
        {
            if(!(year % 400))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    else
    {
        return false;
    }
}

bool Date::isLeapYear() const
{
    return isLeapYear(_year);
}

bool Date::isLeapDay() const
{
    return isLeapDay(_day, _month, _year);
}



int Date::maxDay(int month, int year)
{//the code below was done by me
	if (isLeapYear(year) && month == 2)
	{
		maxDay == 28;
		return;
	}
	switch month;
	{
	case 1, 3, 5, 7, 8, 10, 12:
		
			maxDay = 31;
			break;
		
	case 4, 6, 9, 11:
		
			maxDay = 30:
			break;
		
	}
//I am supposed to use the DAYS_PER_MONTH array, not sure if I did it well
return 31;
}
class="centertext">
void Date::addDay(bool forward) {//the code below was done by me if forward == true; { if today.day = 1; { ++today._month; } if today._month > 12; { today._month = 1; ++today._year; } } else { if (today._day > 1) { --today._day; addDay = _today; } else { --today._month; if (today._month == 0;) { today._month = 12; -- toda._year } today._day = maxDay (today._month, today._year) } } } bool Date::isLeapDay(int day, int month, int year) {//the code below was done by me if (date.day == 29 && date.month is 2 && leapyear(date.year)) { leapday = true; } else { leapday = false; } return false; } void Date::addYears(int years) {//the code below was done by me if (years == 0) { return; } if (today == leapday && (today + years) != leaday) { today._day = 28; } today.year = today.year + years; } void Date::addMonths(int months) {//the code below was done by me if (months == 0) { return; { deltayears = months/12; deltamonths = months % 12; if (months > 0) { if (today._month + deltamonths > 12) { ++deltayears newmonth = (today._month + deltamonths) - 12; } else { newmonth = today.month + deltamonths; } } else //months is negative { if (today._month + deltamonths < 1) { --deltayears; newmonth = today._month + deltamonths + 12; } else { newmonth = today._month + deltamonths; } } if (today._day > maxDay(newmonth, today._year + deltayears) { today._day = maxDay; } today._year = today._year + deltayears today._month = newmonth } void Date::addDays(int days) {//the code below was done by me if(days < 0) { for (count = -1; count--) { addDay(today, false) } } else for (count = 1; count++) { addDay(today, true) } }


date.h

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
#if !defined(DATE_H__)
#define DATE_H__

#include <string>

class Date
{
public:
    Date(int day, int month, int year);
    Date();
    std::string toString() const;
    bool isValid() const;
    static bool isLeapYear(int year);
    bool isLeapYear() const;
    bool isLeapDay() const;

    int getYear() const {if(isValid() == false){} return _year;}
    int getMonth() const {if(isValid() == false){} return _month;}
    int getDay() const {if(isValid() == false){} return _day;}

        
    static bool isLeapDay(int day, int month, int year); 
    void addDay(bool forward);
    static int maxDay(int month, int year);

        
    void addYears(int years);    
    void addMonths(int months);    
    void addDays(int days);   
private:
    
    int _year;
    int _month;
    int _day;
    static const std::string MONTH_STRINGS[];      
    static const int DAYS_PER_MONTH[];
    static const int MIN_MONTH = 1;
    static const int MAX_MONTH = 12;
    static const int MIN_DAY = 1;
};

#endif 


I forgot to add the pseudo code and the output errors I am sorry about that.

Pseudo Code

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
leapday (date)
if date.day is 29 and date.month is 2 and leapyear(date.year)
   leapday = true
else
   leapday = false
endif      
end leapday

maxday (month, year)
if leapyear(year) and month is 2
    maxday is assigned 29
    return;
endif
switch on month
    case 2
        maxday is assigned 28
        return;
    case 1, 3, 5, 7, 8, 10, 12    
        maxday is assigned 31
        return;
    case 4, 6, 9, 11    
        maxday is assigned 30
        return;        
end switch     
end maxday     
     
addDay (forward)
if forward is true
    if today.day is less than maxday (today.month, today.year)
        increment today.day
    else
        today.day is assigned to 1
        increment today.month
        if today.month is greater than 12
            today.month is assigned to 1
            increment today.year
        endif    
    endif
else
    if today.day is greater than 1
        decrement day.today
        addDay is assigned today
    else    
        decrement today.month
        if today.month equals 0
            today.month is assigned 12
            decrement today.year
        endif
        today.day is assigned maxday (today.month, today.year)
    endif
end if
end addDay

     
addYears (int years)
if years is 0
    return
endif    
if today is leapday and (today + years) is not leapday
   today.day is assigned 28
endif   
today.year is assigned today.year + years
end addYears
     
addMonths (months)
if months is 0
    return
endif         
deltayears = months / 12
deltamonths = months mod 12
if months is greater than 0
    if today.month + deltamonths is greater than 12
        increment deltayears 
        newmonth is assigned (today.month + deltamonths) - 12
    else
        newmonth = today.month + deltamonths
    endif
else //months is negative
    if today.month + deltamonths is less than 1
        decrement deltayears
        newmonth is assigned today.month + deltamonths + 12                   
    else
        newmonth = today.month + deltamonths
    endif
endif
if today.day is greater than maxday(newmonth, today.year + deltayears)
   today.day is assigned maxday
endif
today.year is assigned to today.year + deltayears
today.month is assigned newmonth                 
end addMonths

addDays (days)
if days is 0
    return
endif         
if days is less than 0
   for count from -1 to days decrementing
       addDay(today, false)
   end for
else   
   for count from 1 to days 
       addDay(today, true)
   end for
endif   
end addDays


now the errors
[output]date.cpp
date.cpp(40) : warning C4996: 'localtime': This function or variable may be
fe. Consider using localtime_s instead. To disable deprecation, use _CRT_SEC
NO_WARNINGS. See online help for details.
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\time.
112) : see declaration of 'localtime'
date.cpp(123) : error C2446: '==' : no conversion from 'int' to 'int (__cdec
(int,int)'
Conversion from integral type to pointer type requires reinterpret_c
C-style cast or function-style cast
date.cpp(123) : error C2040: '==' : 'int (__cdecl *)(int,int)' differs in le
of indirection from 'int'
date.cpp(123) : warning C4553: '==' : operator has no effect; did you intend
?
date.cpp(124) : error C2561: 'Date::maxDay' : function must return a value
c:\code\cpp\assigment 9\start_files\date.h(25) : see declaration of
e::maxDay'
date.cpp(126) : error C2061: syntax error : identifier 'month'
date.cpp(128) : error C2046: illegal case
date.cpp(130) : error C2659: '=' : function as left operand
date.cpp(131) : error C2043: illegal break
date.cpp(133) : error C2046: illegal case
date.cpp(135) : error C2659: '=' : function as left operand
date.cpp(135) : error C2143: syntax error : missing ';' before ':'
date.cpp(135) : error C2143: syntax error : missing ';' before ':'
date.cpp(147) : error C2061: syntax error : identifier 'forward'
date.cpp(149) : error C2061: syntax error : identifier 'today'
date.cpp(151) : error C2065: 'today' : undeclared identifier
date.cpp(151) : error C2228: left of '._month' must have class/struct/union
type is ''unknown-type''
date.cpp(153) : error C2061: syntax error : identifier 'today'
date.cpp(155) : error C2065: 'today' : undeclared identifier
date.cpp(155) : error C2228: left of '._month' must have class/struct/union
type is ''unknown-type''
date.cpp(156) : error C2065: 'today' : undeclared identifier
date.cpp(156) : error C2228: left of '._year' must have class/struct/union
type is ''unknown-type''
date.cpp(159) : error C2181: illegal else without matching if
date.cpp(161) : error C2065: 'today' : undeclared identifier
date.cpp(161) : error C2228: left of '._day' must have class/struct/union
type is ''unknown-type''
date.cpp(163) : error C2065: 'today' : undeclared identifier
date.cpp(163) : error C2228: left of '._day' must have class/struct/union
type is ''unknown-type''
date.cpp(164) : error C2065: '_today' : undeclared identifier
date.cpp(168) : error C2065: 'today' : undeclared identifier
date.cpp(168) : error C2228: left of '._month' must have class/struct/union
type is ''unknown-type''
date.cpp(170) : error C2065: 'today' : undeclared identifier
date.cpp(170) : error C2228: left of '._month' must have class/struct/union
type is ''unknown-type''
date.cpp(170) : error C2143: syntax error : missing ')' before ';'
date.cpp(170) : error C2059: syntax error : ')'
date.cpp(171) : warning C4390: ';' : empty controlled statement found; is th
he intent?
date.cpp(172) : error C2065: 'today' : undeclared identifier
date.cpp(172) : error C2228: left of '._month' must have class/struct/union
type is ''unknown-type''
date.cpp(173) : error C2065: 'toda' : undeclared identifier
date.cpp(174) : error C2228: left of '._year' must have class/struct/union
type is ''unknown-type''
date.cpp(174) : error C2143: syntax error : missing ';' before '}'
date.cpp(175) : error C2065: 'today' : undeclared identifier
date.cpp(175) : error C2228: left of '._day' must have class/struct/union
type is ''unknown-type''
date.cpp(175) : error C2065: 'today' : undeclared identifier
date.cpp(175) : error C2228: left of '._month' must have class/struct/union
type is ''unknown-type''
date.cpp(175) : error C2065: 'today' : undeclared identifier
date.cpp(175) : error C2228: left of '._year' must have class/struct/union
type is ''unknown-type''
date.cpp(176) : error C2143: syntax error : missing ';' before '}'
date.cpp(184) : error C2065: 'date' : undeclared identifier
date.cpp(184) : error C2228: left of '.day' must have class/struct/union
type is ''unknown-type''
date.cpp(184) : error C2065: 'date' : undeclared identifier
date.cpp(184) : error C2228: left of '.month' must have class/struct/union
type is ''unknown-type''
date.cpp(184) : error C2146: syntax error : missing ')' before identifier 'i
date.cpp(184) : error C2065: 'is' : undeclared identifier
date.cpp(184) : error C2143: syntax error : missing ';' before 'constant'
date.cpp(184) : error C2065: 'date' : undeclared identifier
date.cpp(184) : error C2228: left of '.year' must have class/struct/union
type is ''unknown-type''
date.cpp(184) : error C2059: syntax error : ')'
date.cpp(185) : error C2143: syntax error : missing ';' before '{'
date.cpp(184) : error C3861: 'leapyear': identifier not found
date.cpp(186) : error C2065: 'leapday' : undeclared identifier
date.cpp(188) : error C2181: illegal else without matching if
date.cpp(190) : error C2065: 'leapday' : undeclared identifier
date.cpp(203) : error C2065: 'today' : undeclared identifier
date.cpp(203) : error C2065: 'leapday' : undeclared identifier
date.cpp(203) : error C2065: 'today' : undeclared identifier
date.cpp(203) : error C2065: 'leaday' : undeclared identifier
Believe it or not, the compiler is telling you what you did wrong.

date.cpp:119: warning: statement has no effect
 
		maxDay == 28;
You're using comparison.

date.cpp:120: error: return-statement with no value, in function returning ‘int’
1
2
3
4
5
6
int Date::maxDay(int month, int year)
{//the code below was done by me
	if (isLeapYear(year) && month == 2)
	{
		maxDay == 28;
		return;
No return value!

date.cpp:122: error: expected `(' before ‘month’
 
	switch month;
should be:
 
	switch (month)


date.cpp:124: error: case label ‘1’ not within a switch statement
 
	case 1, 3, 5, 7, 8, 10, 12:
should be:
1
2
3
4
5
6
7
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:


date.cpp:124: error: expected `:' before ‘,’ token
date.cpp:124: error: expected primary-expression before ‘,’ token
date.cpp:124: error: expected `;' before ‘:’ token
date.cpp:127: error: break statement not within loop or switch
date.cpp:129: error: case label ‘4’ not within a switch statement
date.cpp:129: error: expected `:' before ‘,’ token
date.cpp:129: error: expected primary-expression before ‘,’ token
date.cpp:129: error: expected `;' before ‘:’ token
All that crap is related to the bad case syntax.

date.cpp: At global scope:
date.cpp:138: error: expected identifier before ‘=’ token
date.cpp:138: error: expected unqualified-id before ‘=’ token
 
class="centertext">
What is this?
Last edited on
Try to break it down! at least a file with its associated errors in one post.

By the way... is this a function call? ...yes...
then make it: localtime(t); in line 40

I've not really had a look at the code mann it's too huge n I'm feeling sleepy?LOL?
Last edited on
thank you to both of you, I know it is kind of long and stuff, and I feel kinda stupid for not realizing the errors the compiler told me about. I will try to implement the fixes and will re post the solution when done.

@ kbw class="centertext"> is actually some sort of typo.
I mistake I made when writing the post, it is not in the original file. Weird.
Thank you for pointing that out, I will fix the code in the post.

Tried to fix it, but it won't let me post changes. I apologize for that.

I applied the suggested fixes and still I got errors, they are minor errors that I think I can handle. However I don, know what is this one about

date.cpp(123) : error C2040: '==' : 'int (__cdecl *)(int,int)' differs in levels
 of indirection from 'int'


according to visual studio, the expression must be a modifiable value, I don't know what it means.

here is the code after I changed it

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include <iostream>
#include <sstream>
#include <ctime>
#include "date.h"

const std::string Date::MONTH_STRINGS[] = 
{
    "", //one based indexing
    "January",
    "February",
    "March",
    "April",
    "May", 
    "June",
    "July",
    "August",
    "Septenber",
    "October",
    "November",
    "December"
};

const int Date::DAYS_PER_MONTH[] =
{
    0, //one based indexing
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
    
};      



Date::Date(int day, int month, int year) : _year(year), _month(month), _day(day)
{
    isValid();
}

Date::Date()
{
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );
    _year = now -> tm_year + 1900;
    _month = now -> tm_mon + 1;
    _day = now -> tm_mday;
}




std::string Date::toString() const
{
    if(isValid() == false)
    {
        return std::string();
    }
    std::stringstream ss;
    ss  << MONTH_STRINGS[_month] << " " << _day << ", " <<  _year;
    return ss.str();            
}    


bool Date::isValid() const
{
    if(_month < MIN_MONTH || _month > MAX_MONTH)
    {
        std::cerr << "Invalid date " << std::endl;
        return false;
    }
    int daysThisMonth = maxDay(_month, _year);
     
    if(_day < MIN_DAY || _day > daysThisMonth)
    {
        std::cerr << "Invalid date " << std::endl;            
        return false;
        
    }
    
    
    return true;
}

bool Date::isLeapYear(int year)
{
    if(!(year % 4))
    {
        if(!(year % 100))
        {
            if(!(year % 400))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    else
    {
        return false;
    }
}

bool Date::isLeapYear() const
{
    return isLeapYear(_year);
}

bool Date::isLeapDay() const
{
    return isLeapDay(_day, _month, _year);
}



int Date::maxDay(int month, int year)
{
	if (isLeapYear(year) && month == 2)
	{
		maxDay == 29;
		return maxDay;
	}
	switch (month)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		
			maxDay = 31;
			break;
		
	case 4:
	case 6: 
	case 9: 
	case 11:
		
			maxDay = 30:
			break;
		
	}
//this has been modified.
//Use the DAYS_PER_MONTH array
return 31;
}


void Date::addDay(bool forward)
{
	if forward == true;
	{
		if today.day = 1;
		{
			++today._month;
		}
		if today._month > 12;
		{
			today._month = 1;
			++today._year;
		}
	}
	else
	{
		if (today._day > 1)
		{
			--today._day;
			addDay = _today;
		}
		else
		{
			--today._month;
		
		if (today._month == 0;)
		{
			today._month = 12;
			-- toda._year
		}
			today._day = maxDay (today._month, today._year)
		}
	}
//this has been already modified and will hopefully work.
}


bool Date::isLeapDay(int day, int month, int year) 
{
	if (date.day == 29 && date.month is 2 && leapyear(date.year))
	{
		leapday = true;
	}
	else
	{
		leapday = false;
	}
//this has been modified.
return false;
}


void Date::addYears(int years)
{
	if (years == 0)
	{
		return;
	}
	if (today == leapday && (today + years) != leaday)
	{
		today._day = 28;
	}
	today.year = today.year + years;
//this has been modified.
}
    
void Date::addMonths(int months)    
{
	if (months == 0)
	{
		return;
	{
	deltayears = months/12;
	deltamonths = months % 12;
	if (months > 0)
	{
		if (today._month + deltamonths > 12)
		{
		++deltayears
		newmonth = (today._month + deltamonths) - 12;
		}
		else
		{
			newmonth = today.month + deltamonths;
		}
	}
	else //months is negative
	{
		if (today._month + deltamonths < 1)
		{
			--deltayears;
			newmonth = today._month + deltamonths + 12;
		}
		else
		{
			newmonth = today._month + deltamonths;
		}
	}
	if (today._day > maxDay(newmonth, today._year + deltayears)
	{
		today._day = maxDay;
	}
	today._year = today._year + deltayears
	today._month = newmonth
//this has been modified.
}

void Date::addDays(int days)
{
	if(days < 0)
	{
		for (count = -1; count--)
		{
			addDay(today, false)
		}
	}
	else
		for (count = 1; count++)
		{
			addDay(today, true)
		}
//this has been modified.
}
Last edited on
You're mistakenly using comparison instead of assignment. It's a common mistake because it's vaild C and C++.
 
		maxDay == 29;
should be:
 
		maxDay = 29;

But you haven't declared maxDay as far as I can tell.
Last edited on
Topic archived. No new replies allowed.