Syntax error with a function

I am working on a code which will allow me to print out a calendar given the year and the starting day of the week for jan 1st (0=sun...6=sat).

I've come to the conclusion that the simplest way to make this program with my current knowledge of c++ would be to have one function that gets called from main several times in order to print out my calendar. I am a beginner and very unskilled in this language so I keep having syntax errors with my function. If you could help me identify what my problem is and why my code will not execute properly i would greatly appreciate that.

int year;
int month;
int startingday;
int a;
int calendar();
int cal;
int main()

{
cout << "What is the year?" << endl;
cin >> year;
cout << "What day of the week does January 1st start on?" << "\n" << "0 = Sunday...6 = Saturday." << endl;
cin >> startingday;
cout << "**Calendar for "<< year << endl;
cal = int calendar();
cout << cal << endl;
return 0;

}
int calendar()
{
int a;
for (month = 0; month < 12; month++)
cout << "Sun " << "Mon " <<"Tues "<<"Weds "<<"Thur "<<"Fri "<<"Sat "<< endl;
cin >> a;
return a;
}
Please use the code formatting tags (<>) on the right. It makes reading the code a whole lot easier.

I don't quite understand what you're trying to do with your code at the moment but this is why you're getting a syntax error.
 
cal = int calendar();

Remove the int and you're all set.

At the moment, all the code does is print the days of the week on each line, 12 times. If you want to print out a calendar, you would need to determine the number of days in the month and print out the days of the week up until that last day.

Also, why are your variables global? Read this: http://www.cplusplus.com/forum/beginner/174778/

Edit: fixed 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
#include <iostream>
using std::cout; using std::cin; using std::endl;

void calendar();

int main()
{
	int year = 0, month = 0, startingday = 0;
	
	cout << "What is the year?" << endl;
	cin >> year;
	cout << "What day of the week does January 1st start on?\n" << "0 = Sunday...6 = Saturday." << endl;
	cin >> startingday;
	cout << "**Calendar for " << year << endl;
	
	calendar();
	
	return 0;
}

void calendar()
{
	for (int month = 0; month < 12; month++)
		cout << "Sun " << "Mon " << "Tues " << "Weds " << "Thur " << "Fri " << "Sat " << endl;
}
Last edited on
Topic archived. No new replies allowed.