calendar dates

I have to write a program that will list each month of the year and the day of the week that the month begins on. The program will take as input the year and the day of the week that January 1st falls on in that year. Assume that a leapĀ· year is any year which is divisible by 4.

Samples of input and output for correctly running programs:

1st Example
EXAMPLE INPUT:
Please enter the year: 2013
Please enter the day of the week for the first day of the year
(0-Sunday, 6-Saturday): 2
EXAMPLE OUTPUT:
January starts on a Tuesday
February starts on a Friday
March starts on a Friday
April starts on a Monday
May starts on a Wednesday
June starts on a Saturday
July starts on a Monday
August starts on a Thursday
September starts on a Sunday
October starts on a Tuesday
November starts on a Friday
December starts on a Sunday

2nd Example
EXAMPLE INPUT:
Please enter the year: 2012
Please enter the day of the week for the first day of the year
(0-Sunday, 6-Saturday): 0
EXAMPLE OUTPUT:
January starts on a Sunday
February starts on a Wednesday
March starts on a Thursday
April starts on a Sunday
May starts on a Tuesday
June starts on a Friday
July starts on a Sunday
August starts on a Wednesday
September starts on a Saturday
October starts on a Monday
November starts on a Thursday
December starts on a Saturday
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#include <iostream>
using namespace std;
int main()
{
  int year;
  int daysinyear;
  int yearstartson;
  int dayofweek = 0;

  
  
  
  
  cout<<"Enter the year: ";
  cin>>year;
  if(year%4 == 0)
  {
    daysinyear = 366;
  }
  else
  {
    daysinyear = 365;
  }
  cout<<"Please enter the day of the week for the first day of the year"<<endl;
  cout<<"(0-Sunday, 6-Saturday): ";
  cin>>dayofweek;
  
  for(int i = 1; i<=daysinyear; i++)
  {
    if(dayofweek == 7)
    {
      dayofweek = 0;
    }
    if(i == 1)
    {
      cout<<"January starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 32)
    {
      cout<<"febuary starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 60)
    {
      cout<<"March starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 91)
    {
      cout<<"April starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 121)
    {
      cout<<"May starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 152)
    {
      cout<<"june starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 182)
    {
      cout<<"july starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 213)
    {
      cout<<"August starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 244)
    {
      cout<<"September starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 274)
    {
      cout<<"October starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 305)
    {
      cout<<"November starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    if(i == 335)
    {
      cout<<"December starts on ";
      if(dayofweek == 0)
      {
        cout<<"Sunday"<<endl;
      }
      if(dayofweek == 1)
      {
        cout<<"Monday"<<endl;
      }
      else if(dayofweek == 2)
      {
        cout<<"Tuesday"<<endl;
      }
      else if(dayofweek == 3)
      {
        cout<<"Wednesday"<<endl;
      }
      else if(dayofweek == 4)
      {
        cout<<"Thursday"<<endl;
      }
      else if(dayofweek == 5)
      {
        cout<<"Friday"<<endl;
      }
      else if(dayofweek == 6)
      {
        cout<<"Saturday"<<endl;
      }
    }
    dayofweek++;
  }
}[code]
[/code]


this is some of my code, it partly works but i feel is too lengthy. How can i cut this code down to make it more compact
closed account (48T7M4Gy)
Give each day of the year a day number from 1-365 or 1-366 for leap years. Using modular arithmetic the day can be determined if you know the starting day.

Arrays of days per month and day names are very useful here. You only need one if, to determine leap years. Probably about 20 lines max.
Topic archived. No new replies allowed.