Calendar Help (need to combine my code into a single function)

The assignment reads "Write a void function named displayCalendarDays. This function is passed two input parameters. The first parameter is an int that represents the start day. Start days are numbered from 0 to 6 with 0 representing Sunday and 6 representing Saturday. The second parameter is an int that represents the number of days in the month. If the start day is not in the range 0 to 6 inclusive or if the number of days is not in the range 1 to 31 inclusive, the program should display a helpful error message instead of displaying a calendar. If the parameters are OK, the program should display the numbers for the calendar as they would appear on a typical calendar."
I have two separate bits of code already written out I'm just a little lost how to combine the code to satisfy the criteria, any and all help would be appreciated
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
void displayCalendarDays ( int startDay, int daysInMonth);
{
	cout << "How many days are in this month?" << endl;
	cin >> daysInMonth;
	
	cout << "What day does the month start with (Sunday would equal 0)?" << endl;
	cin >> startDay;

	if(daysInMonth < 1 || daysInMonth > 31 || startDay < 0 || startDay > 6)
		{ cout << " You should reread the program instructions and try again." << endl;
		}
	else if(daysInMonth >= 1 || daysInMonth <= 31 || startDay >= 0 || startDay <= 6)

for(int i = startDay; i <= days; i++){ 
if((i == 0) || (i == 7) || (i == 14) || (i == 21) || (i == 29)){ 
cout << i <<" - " << "Sunday" << endl; 
} 
if((i == 1) || (i == 8) || (i == 15) || (i == 22) || (i == 30)){ 
cout << i <<" - " << "Monday" << endl; 
} 
if((i == 2) || (i == 9) || (i == 16) || (i == 23) || (i == 31)){ 
cout << i <<" - " << "Tuesday" << endl; 
} 
if((i == 3) || (i == 10) || (i == 17) || (i == 25)){ 
cout << i <<" - " << "Wednesday" << endl; 
} 
if((i == 4) || (i == 11) || (i == 18) || (i == 26)){ 
cout << i <<" - " << "Thursday" << endl; 
} 
if((i == 5) || (i == 12) || (i == 19) || (i == 27)){ 
cout << i <<" - " << "Friday" << endl; 
} 
if((i == 6) || (i == 13) || (i == 20) || (i == 28)){ 
cout << i <<" - " << "Saturday" << endl; 
} 
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void disp(const int startDay, const int days)
{
  if (startDay < 0 || startDay > 6 || days > 31) {
    cout << "Error\n";
    return
  }
  string names[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  for (int j = 0; j < 7; j++) {
    cout << names[j];
    for (int i = j - startDay + 1; i <= days; i+=7) {
      cout << '\t';
      if (i > 0) cout << i;
    }
   cout << endl;
  }
}
Topic archived. No new replies allowed.