Concerns with function implementation for c++ project

closed account (9G1TpfjN)
I'm currently putting together a birthday calculator project in school and am having a hard time getting my code to compile. I am also unsure if my functions are being called correctly in main. Can someone please offer some constructive suggestions that might help steer me in the right direction? Also, I keep getting a "function definition not allowed here" message for the definition of determineDay and all function definitions below it. Just to note, the last function requires a loop which I have not finished yet. My main concern right now is making sure my functions can all work properly together and be successfully called in main.

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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

void printHeading();

void printCloser();

void printMenu();

int getMenuChoice();

bool isGregorianDate(int month, int day, int year);

bool isLeapYear(int year);

bool isValidDate(int month, int day, int year);

int determineDay(int month, int day, int year);

void printDayOfBirth(int day);

void determineDayOfBirth();

void print10Birthdays();

void print10LeapYears();

int main() {
    
    printHeading();
    
    getMenuChoice();
    
    determineDayOfBirth();
    
    print10Birthdays();
    
    print10LeapYears();
    
    printCloser();
    
    return 0;
}

void printHeading() {
    cout << "*******************************" << endl
         << "      Birthday Calculator      " << endl
         << "*******************************" << endl << endl;
    return;
}


void printCloser() {
    cout << endl;
    cout << "****************************************************" << endl
         << "      Thanks for using the Birthday Calculator      " << endl
         << "****************************************************" << endl
         << endl;
    return;
}


void printMenu() {
    
    cout << endl;
    cout << "Menu Options" << endl
         << "------------" << endl;
    cout << "1) Determine day of birth" << endl;
    cout << "2) Print the next 10 leap years" << endl;
    cout << "3) Determine birthdays for the next 10 years" << endl;
    cout << "4) Finished" << endl << endl;
    
    cout << "Choice --> " << getMenuChoice();
    
    return;
}

int getMenuChoice() {
    
    int menuChoice;
    
    cin >> menuChoice;
    
    if (menuChoice == 1)  {
        
        determineDayOfBirth();
    }
    
    if (menuChoice == 2)  {
        
        print10LeapYears();
        
    }
    
    if (menuChoice == 3)  {
    
        determineDayOfBirth();
        
    }
    
    if (menuChoice == 4)  {
        
        cout << "Finished" << endl;
        
    }
    
    else  {
        
        cout << "Invalid menu choice";
        
    }
    
    return 0;
}

bool isGregorianDate(int month, int day, int year)  {

    if (year > 1752)  {

       return true;
        
    }
    
    if ( (year == 1752) && (month == 9) && (day > 13) )  {
            
       return true;
            
        }
    
    if ( (year == 1752) && (month > 9) )  {
        
        return true;
        
    }
        
    else  {
        
    // returning false to avoid compile error
       return false;
        
    }
    
}

bool isLeapYear(int year)  {
    
    if ((year % 4 == 0 && year % 100!=0) || (year % 400 == 0) || (year > 1582))  {
        
        return true;
        
    }
    else  {
        
        return false;
        
    }
    
    // returning 0 to avoid compile error
    return 0;
}


bool isValidDate(int month, int day, int year)  {
    
    if ( (month == 9) || (month == 4) || (month == 6) || (month == 11) )  {
        
        if ( (day <= 30) && (day > 0) )
            
            if (bool isGregorianDate = true)
            
            return true;
            
        }
    
    if ( (month == 1) && (day <= 31) && (day > 0) )  {
        
        if (bool isGregorianDate = true)
        
        return true;
        
    }
    
    if ( (month > 2) && (month <=8) && (day <= 31) && (day > 0) ) {
        
        if (bool isGregorianDate = true)
     
        return true;
        
    }
    
    if  ( (month == 10) && (day <= 31) && (day <= 31) && (day > 0))  {
        
        if (bool isGregorianDate = true)
        
        return true;
        
    }
        
    if  ( (month == 12) && (day <= 31) && (day > 0) )  {
        
        if (bool isGregorianDate = true)
        
        return true;
            
        }
        
        if  ( (month == 2) && (day <= 28) && (day > 0) )  {
            
            if (bool isGregorianDate = true)
            
                if (bool isLeapYear = false)
                
                return true;
            
        }
            
        if  ( (month == 2) && (day <= 29) && (day > 0) )  {
            
            if (bool isGregorianDate = true)
            
            if (bool isLeapYear = true)
                
                return true;
            
        }
        
        else  {
    
    // returning false to avoid compile error
    return false;
            
        }



    int determineDay(int month, int day, int year)  {
    
    if (month == 1)  {
        
        month = 13;
        
        year = year - 1;
        
    }
    
    if (month == 2)  {
        
        month = 14;
        
        year = year - 1;
        
    }
    
    int zellersResult;
    
    zellersResult = ((day + (13 * (month + 1) / 5) + year%100 + (year%100 / 4) + (floor(year/100) / 4) + (5 * floor(year/100)) % 7);
                     
    // returning 0 to avoid compile error
    return 0;
                     
}
                     


void printDayOfBirth(int day)  {
    
    if (zellersResult = 0)  {
        
        cout << "Saturday";
        
    }
    
    if (zellersResult = 1)  {
        
        cout << "Sunday";
        
    }
    
    if (zellersResult = 2)  {
        
        cout << "Monday";
        
    }
    
    if (zellersResult = 3)  {
        
        cout << "Tuesday";
        
    }
    
    if (zellersResult = 4)  {
        
        cout << "Wednesday";
        
    }
    
    if (zellersResult = 5)  {
        
        cout << "Thursday";
        
    }
    
    if (zellersResult = 6)  {
        
        cout << "Friday";
        
    }
    
    return;
}


void determineDayOfBirth()  {
    
    bool isValidDate();
    int determineDay();
    void printDayOfBirth();
    
    cout << "Enter your date of birth" << endl;
    cout << "format: month / day / year  -->" << " ";
    
    char inputSlash = '/';
    
    cin >> month;
    cout << " ";
    cin >> inputSlash;
    cout << " ";
    cin >> day;
    cout << " ";
    cin >> inputSlash;
    cout << " ";
    cin >> year;
    
    if (isValidDate == true)  {
    
        determineDay();
        
        cout << You were born on a: << " " << printDayOfBirth() << endl;
        cout << Have a great birthday!!! << endl;
    }
    
    if (isValidDate == false)  {
        
        cout << "Invalid date" << endl;
        
    }
    
    return;
}

void print10Birthdays()  {

    cout << "Under Construction" << endl;

    return;
}

void print10LeapYears()  {
    
    int year;
    bool isGregorianDate();
    bool isLeapYear();
    
    cout << "Enter year" --> << " ";
    cin >> year;
    
    if (isGregorianDate(year) == true)  {
        
        isLeapYear(year);
        
    }
        
    if (isLeapYear(year) == true)  {
    
    cout << Leap year is <<
        
    }
    
    else  {
        
    }
    
    return;
    
}
                     }

Last edited on
Your function isValidDate doesn't have a closing } so the next function is still inside isValidDate.
Topic archived. No new replies allowed.