function calling, yearly calendar

I understand my start_day and num_day are undeclared right now. However, I am not understanding the concept of calling on a function. I am trying to call on a function to display a yearly calendar. As it stands right now I am generating a monthly calendar with the two inputs at the beginning. Basically the function i want to call is the calendar(month) at the bottom. Do i move this outside of the main function?

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
#include <iostream>
#include <iomanip>
using namespace std;


int print_month(int num_day, int start_day);
int main(void)
{
   int print_month(int num_day, int start_day);
   char month_length[12] ={31,28,31,30,31,30,31,31,30,31,30,31};//non leap year
   char month_leap[12]= {31,29,31,30,31,30,31,31,30,31,30,31};//leap year
   char month_names[12][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};


   int blanks;                      // number of blank spaces before first day
   int i;                           // index for looping through each day
   int valid_input = 1;             // flag to track whether valid input is obtained
   int leap_year;                   // if it is a leap year or if it is not
   int day_year;                    // what day the year starts on


   cout << "\nIs the year a leap year (0=No, 1=Yes)";
   cin >> leap_year;
   if (leap_year <0 || leap_year >1)
   {
      cout << "The number for a leap year is incorrect.\n";
      cout << "Is the year a leap year (0=No, 1=Yes)";
      cin >> leap_year;
      if (leap_year < 0 || leap_year > 1)
      {
         valid_input = 0;
      } 
   }


   if (valid_input)
   {
      cout << "Enter day of week on which year starts (1=Sun, 7=Sat): ";
      cin >> day_year;
      if (day_year < 1 || day_year > 7)
      {
         cout << "\nThe day the year starts on must be a choice of one of these options:\n";
         cout << "   1 for Sunday\n   2 for Monday\n   3 for Tuesday\n   4 for Wednesday\n   5 for Thursday\n   6 for Friday\n   7 for Saturday\n";
         cout << "Enter day the year starts on: ";
         cin >> day_year;
         if (day_year < 1 || day_year > 7)
         {
            valid_input = 0;
         }
       }
    }
   if (valid_input)// if both input numbers are valid, then display calendar
   {
      blanks = start_day - 1; // Find how many blank spaces to insert before the first day
       cout << "\nSun Mon Tue Wed Thu Fri Sat\n\n"; // display heading
      // Display days
      if (blanks > 0)
      {
         for(i=0;i<blanks;i++)cout<<" ";
           }


         for (i = 1; i <= num_days; i++)
           {
         cout << setw(3) << i;   // format i right-aligned space 3 wide
         if ((i + blanks) % 7 == 0)
         {
            cout << "\n";
         } 
                else
                    {
                     cout << " ";
                    }
       }
that did help, but it keeps saying that i have an expected initializer before int, also those calls reference in that article were very basic is this setup correct. My main function is on top with the rest of it below the condition statements
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
  
#include <iostream>
#include <iomanip>
using namespace std;


int print_month(int num_day, int start_day)


int main(void)
{
  
  char month_length[12] ={31,28,31,30,31,30,31,31,30,31,30,31};     //non leap year
  char month_leap[12]= {31,29,31,30,31,30,31,31,30,31,30,31};       //leap year
  char month_names[12][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};//
  int blanks;                  // number of blank spaces before first day
  int j;                       // index for looping through each day
  int valid_input = 1;         // flag to track whether valid input is obtained
  int leap_year;               // if it is a leap year or if it is not
  int day_year;                // what day the year starts on
  
  cout << "\nIs the year a leap year (0=No, 1=Yes)";
  cin >> leap_year;
  if (leap_year <0 || leap_year >1)
    
    {
      cout << "The number for a leap year is incorrect.\n";
      cout << "Is the year a leap year (0=No, 1=Yes)";
      cin >> leap_year;
      if (leap_year < 0 || leap_year > 1)
	{
	  valid_input = 0;
	}
    }
  if (valid_input)
    {
      cout << "Enter day of week on which year starts (1=Sun, 7=Sat): ";
      cin >> day_year;
      if (day_year < 1 || day_year > 7)
	{
	  cout << "\nThe day the year starts on must be a choice of one of these options:\n";
	  cout << "   1 for Sunday\n   2 for Monday\n   3 for Tuesday\n   4 for Wednesday\n   5 for Thursday\n   6 for Friday\n   7 for Saturday\n";
	  cout << "Enter day the year starts on: ";
	  cin >> day_year;
	  if (day_year < 1 || day_year > 7)
	    {
	      valid_input = 0;
	    }
       	}
    }                                               // if both input numbers are valid, then display calendar


  for (j=0; j<12; j++)
    {
      cout << month_names[j] << endl;
      print_month (num_days[j], start_day);
    }
  return 0;
}






int print_month(int num_day, int start_day)
{
  
  blanks = day_year - 1;                         // Find how many blank spaces to insert before the first day
  cout << "\nSun Mon Tue Wed Thu Fri Sat\n\n";         // Display days
  if (blanks > 0)
    {
      for(i=0;i<blanks;i++)
	{
	  cout<<""; 
	}
    }
  for (i = 1; i <= 31; i++)
    {
      cout << setw(3) << right << i;              // format i right-aligned space 3 wide
      if ((i + blanks) % 7 == 0)
	{
	  cout << "\n";
	} 
      else
	{
	  cout << " "<< endl;
	}


 else                                                // if input isn’t valid, then display message
   {
      cout << "The input obtained was invalid and can’t be used to print a calendar.\n";
   }
   return (start_day);
}
error: expected initializer before 'int'
You missed a semicolon at the end of line 7
ok well that sucks, i am going to work on this a while then repost what i get because that showed a few errors.
ok so i was able to finally get the thing to output a yearly calendar, however now it has gotten rid of my number associated with the calendar and it is adding a number before the month title

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
  #include <iostream>
#include <iomanip>
using namespace std;




int print_month(int num_day, int start_day);


int main(void)
{
    
    char month_length[12] ={31,28,31,30,31,30,31,31,30,31,30,31};     //non leap year
    char month_leap[12]= {31,29,31,30,31,30,31,31,30,31,30,31};       //leap year
    char month_names[12][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    int num_day;	
    int start_day;
    int blanks;                     // number of blank spaces before first day  
    int valid_input = 1;         // flag to track whether valid input is obtained
    int leap_year;               // if it is a leap year or if it is not
    int day_year;                // what day the year starts on
    
    cout << "\nIs the year a leap year (0=No, 1=Yes)";
    cin >> leap_year;
    if (leap_year <0 || leap_year >1)
        
    {
        cout << "The number for a leap year is incorrect.\n";
        cout << "Is the year a leap year (0=No, 1=Yes)";
        cin >> leap_year;
        if (leap_year < 0 || leap_year > 1)
        {
            valid_input = 0;
        }
    }
    if (valid_input)
    {
        cout << "Enter day of week on which year starts (1=Sun, 7=Sat): ";
        cin >> day_year;
        if (day_year < 1 || day_year > 7)
        {
            cout << "\nThe day the year starts on must be a choice of one of these options:\n";
            cout << "   1 for Sunday\n   2 for Monday\n   3 for Tuesday\n   4 for Wednesday\n   5 for Thursday\n   6 for Friday\n   7 for Saturday\n";
            cout << "Enter day the year starts on: ";
            cin >> day_year;
            if (day_year < 1 || day_year > 7)
            {
                valid_input = 0;
            }
       	}
    }                                               // if both input numbers are valid, then display calendar
    
    
    for (int j=0; j<12; j++)
    {
        cout << month_names[j];
        cout << print_month (month_length[j], start_day);
    }
    return 0;
}












int print_month(int num_day, int start_day)
{
    int blanks=start_day-1;
                        
    cout << "\nSun Mon Tue Wed Thu Fri Sat\n\n";     // Display days
    if (blanks > 0)                                  // Is the first line of the month
    {
 for(int i=0; i< blanks; i++) 
        {
	cout<<"";
	}
    }
 for (int i=1; 1<= start_day; i++)
{
cout << setw(3)<< right<< i;
if((i+blanks)%7==0)
{
cout << "\n";
} 
else
{
cout << " "<< endl;
}
   
        return (start_day);


}
}


the issue is between the screen and the chair
ok i am getting closer, i had a lot of formatting errors and the biggest was my return (start_day) was in the wrong place, now i am just needing to work on formatting then add in the leap year
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
  int print_month(int num_day, int start_day);


int main(void)
{
    
    char month_length[12] ={31,28,31,30,31,30,31,31,30,31,30,31};     //non leap year
    char month_leap[12]= {31,29,31,30,31,30,31,31,30,31,30,31};       //leap year
    char month_names[12][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    int num_day;	
    int start_day;
    int blanks;                  // number of blank spaces before first day  
    int valid_input;      // flag to track whether valid input is obtained
    int leap_year;               // if it is a leap year or if it is not
    int day_year;                // what day the year starts on
    
    cout << "\nIs the year a leap year (0=No, 1=Yes)";
    cin >> leap_year;
    if (leap_year <0 || leap_year >1)
        
    {
        cout << "The number for a leap year is incorrect.\n";
        cout << "Is the year a leap year (0=No, 1=Yes)";
        cin >> leap_year;
        if (leap_year < 0 || leap_year > 1)
        {
            valid_input = 0;
        }
    }
    if (valid_input)
    {
        cout << "Enter day of week on which year starts (1=Sun, 7=Sat): ";
        cin >> day_year;
        if (day_year < 1 || day_year > 7)
        {
            cout << "\nThe day the year starts on must be a choice of one of these options:\n";
            cout << "   1 for Sunday\n   2 for Monday\n   3 for Tuesday\n   4 for Wednesday\n   5 for Thursday\n   6 for Friday\n   7 for Saturday\n";
            cout << "Enter day the year starts on: ";
            cin >> day_year;
            if (day_year < 1 || day_year > 7)
            {
                valid_input = 0;
            }
       	}
    }                                               // if both input numbers are valid, then display calendar
    
    
    for (int j=0; j<12; j++)
    {
        cout << month_names[j];
        print_month (month_length[j], day_year);
    }
    return start_day;
}


int print_month(int num_day, int start_day)
{	
    int blanks=start_day-1;
                        
    cout << "\nSun Mon Tue Wed Thu Fri Sat\n\n";     // Display days
    if (blanks > 0)                                  // Is the first line of the month
    {
 for(int i=0; i< blanks; i++) 
        {
	cout<<"";
	}
    }
 for (int i=1; i<= num_day; i++)
{
cout << setw(3)<< right<< i;
if((i+blanks)%7==0)
{
cout << "\n";
} 
else
{
cout << " "<< endl;
}
}   
        return (start_day);


}
why is this wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
     if (blanks > 0)                                  // Is the first line of the month
    {
 for(int i=0; i< blanks; i++) 
        {
	cout<<"";
	}
cout << setw(3)<< right<< i;
if((i+blanks)%7==0)
{
cout << "\n";
} 
else
{
cout << " "<< endl;
}

is what i ended with and worked.


int i; //i is a variable for print spacing in calendar
if (start_day > 0)
{
for (i = 0; i < start_day-1; i++) cout<< " ";
}
for (i = 1; i <= num_days; i++)
{
cout << setw(3) << i; //Setting variable i with spacing to the right of 3
if ((i + start_day-1)%7 == 0)
{
cout << "\n";
}
else
{
cout << " ";
}

}
cout << "\n\n";

int end_day; //Variable for the day a month ends and where the other one should start
end_day = ((start_day + num_days) % 7);
if(end_day == 0) //Condition for when the last day is Saturday
{
end_day = 7;
}
Topic archived. No new replies allowed.