So I was trying to make a calender that outputs what ever month is prompted. yet this wont run, i keep getting this error
1>c:\users\lukas shininger\documents\visual studio 2008\projects\calender2\calender2\calender.cpp(151) : error C2059: syntax error : '}'

#include <iostream>
#include <string>
using namespace std;
int main(){

	int month,dateCount,dayCount,blankCount,totalDates,i;
	/*month: userinput variable between 1 and 12
	 dateCount: a counter to iterate through the dates of a specific month
	 dayCount: a counter to iterate from 0 to 6 (Sunday to Saturday)
	 blankCount: a counter to align the first day of a month to a specific day of the week
	 totalDate: the total number of days in a specific month
	 i: a general counter
	 */
	 
	string monthName;// a string to store the name of a month
	char flag;//flag to determine if the user wants to continue
	
	cout <<"I will display the calendar for the month you choose in 2008.\n";
	do{
		cout << "please input the month you wish to see corisponding with its number.\n";
			cin >> month;
		
		/* Based on the user input, obtain the name of a month, the totalDates, and the day of the first day in that month (blankCount)
		
		use a switch statement to switch on the month value
		 for each case, assign the name of the month to monthName
						assign value to the total dates
						calculate the blankCount
		 case 1 is given as an example
		*/
		switch (month){
			case 1:
				monthName="January";
				totalDates=31;
				blankCount=2;
				
				break;
				switch (month)
			case 2:
				monthName="Febuary";
				totalDates=29;
				blankCount=5;
				
				break;
		switch (month)
			case 3:
				monthName="March";
				totalDates=31;
				blankCount=6;
				
				break;
		switch (month)
			case 4:
				monthName="April";
				totalDates=30;
				blankCount=2;
				
				break;
		switch (month)
			case 5:
				monthName="May";
				totalDates=31;
				blankCount=4;
				
				break;
		switch (month)
			case 6:
				monthName="June";
				totalDates=30;
				blankCount=0;
				
				break;
		switch (month)
			case 7:
				monthName="July";
				totalDates=31;
				blankCount=2;
			
				break;
		switch (month)
			case 8:
				monthName="August";
				totalDates=31;
				blankCount=5;
				
				break;
		switch (month)
			case 9:
				monthName="September";
				totalDates=30;
				blankCount=1;
				
				break;
		switch (month)
			case 10:
				monthName="October";
				totalDates=31;
				blankCount=3;
				
				break;
		switch (month)
			case 11:
				monthName="November";
				totalDates=30;
				blankCount=6;
				
				break;
		switch (month)
			case 12:
				monthName="December";
				totalDates=31;
				blankCount=1;
				
				break;}
			/* write out other cases and default below*/
				
		
		
		/* after the switch statement, you should have obtained the monthName, totalDates, and the number of 
		 blanks (i.e. blankCount) for that month*/
		cout << monthName << "2008\n";
		/*output headers here*/
		cout <<"Sun\tMon\tTues\tWed\tThurs\tFri\tSat\n";
		cout <<"===\t===\t===\t===\t===\t===\t===\n";
		
		//output blanks to prepare for the first day of month. Use a for statement here
		for (i=1;i<=blankCount; i++){
			cout <<"  \t";
		}
		for(i=1; i <= totalDates; i++){
			cout << i << "\t";
			dayCount++;
				if (dayCount==7){
					cout << "\n";
				dayCount=0;}
				
				

		
		//output the calendar below
		cout << "Do you wish to see another month? Y/N or y/n?\n";
		cin >> flag;
		
		//check if the user wants to continue or not
		}
	while(flag != 'n' || flag != 'N');
	
	cout <<"\n\nAll done. Bye";
	return 0;
	
}}

Recommended Answers

All 5 Replies

Your program has mismatched { and }. If you would use better formatting then such errors will be easier to find. As it is, it is very difficult and time consuming to find matching { and }. Here is an example of what I suggest:

for(i=1; i <= totalDates; i++)
{
    cout << i << "\t";
    dayCount++;
    if (dayCount==7)
    {
        cout << "\n";
        dayCount=0;
    }
    //output the calendar below
    cout << "Do you wish to see another month? Y/N or y/n?\n";
    cin >> flag;
		
    //check if the user wants to continue or not
}

You just didn't have the end of the do while in the right spot. The double }} at the end is wrong.

Plus, there are too many switch calls. You just need to call it once at the top.

As Ancient Dragon suggested, you should try to organize your code so that it's easier to read. Indenting is great for that, and commenting when you get to the end of a long loop or statement is helpful.

When I ran your code, the first line of most months ran off the end. You will need to give dayCount a value in each case so that it works right.


Personal suggestion, you might want to make a list after your "please input the month you wish to see corisponding with its number.\n" line so that the user understands what it wanted of them. I'd suggest doing something sorta like
1=Jan 2=Feb 3=Mar ... etc
so it makes it clear what you want.

You might also want to put a ( cout << "\n\n"; ) or something like that after ( cin >> flag; ) so that it will help separate the cases and make things easier to read.

ok so i have this working now, but some months run off of the calender and i have no idea why?

#include <iostream>
#include <string>
using namespace std;
int main(){

	int month,dateCount,dayCount=0,blankCount=0,totalDates=0,i;
	/*month: userinput variable between 1 and 12
	 dateCount: a counter to iterate through the dates of a specific month
	 dayCount: a counter to iterate from 0 to 6 (Sunday to Saturday)
	 blankCount: a counter to align the first day of a month to a specific day of the week
	 totalDate: the total number of days in a specific month
	 i: a general counter
	 */
	 
	string monthName;// a string to store the name of a month
	char flag = 0;//flag to determine if the user wants to continue
	
	cout <<"I will display the calendar for the month you choose in 2008.\n";
	do{
		cout << "\n";
		cout << "please input the month you wish to see corisponding with its number.\n";
			cin >> month;
		
		/* Based on the user input, obtain the name of a month, the totalDates, and the day of the first day in that month (blankCount)
		
		use a switch statement to switch on the month value
		 for each case, assign the name of the month to monthName
						assign value to the total dates
						calculate the blankCount
		 case 1 is given as an example
		*/
		switch (month){
			case 1:
				monthName="January";
				totalDates=31;
				blankCount=2;
				
				break;
			
			case 2:
				monthName="Febuary";
				totalDates=29;
				blankCount=5;
				
				break;
		
			case 3:
				monthName="March";
				totalDates=31;
				blankCount=6;
				
				break;
		
			case 4:
				monthName="April";
				totalDates=30;
				blankCount=2;
				
				break;
		
			case 5:
				monthName="May";
				totalDates=31;
				blankCount=4;
				
				break;
		
			case 6:
				monthName="June";
				totalDates=30;
				blankCount=0;
				
				break;
		
			case 7:
				monthName="July";
				totalDates=31;
				blankCount=2;
			
				break;
		
			case 8:
				monthName="August";
				totalDates=31;
				blankCount=5;
				
				break;
		
			case 9:
				monthName="September";
				totalDates=30;
				blankCount=1;
				
				break;
		
			case 10:
				monthName="October";
				totalDates=31;
				blankCount=3;
				
				break;
		
			case 11:
				monthName="November";
				totalDates=30;
				blankCount=6;
				
				break;
		
			case 12:
				monthName="December";
				totalDates=31;
				blankCount=1;
				
				break;}
			/* write out other cases and default below*/
				
		
		
		/* after the switch statement, you should have obtained the monthName, totalDates, and the number of 
		 blanks (i.e. blankCount) for that month*/
		cout << monthName << "2008\n";
		/*output headers here*/
		cout <<"Sun\tMon\tTues\tWed\tThurs\tFri\tSat\n";
		cout <<"===\t===\t===\t===\t===\t===\t===\n";
		
		//output blanks to prepare for the first day of month. Use a for statement here
				for (i=1;i<=blankCount; i++){
			cout <<"  \t";
		}
		for(i=1; i <= totalDates; i++){
			cout << i << "\t";
			dayCount++;
				if (dayCount==7){
					cout << "\n";
				dayCount=0;}
		}
	cout << "\n";
		 cout << "Do you wish to see another month? Y/N or y/n?\n";
    cin >> flag;

    break;
		//check if the user wants to continue or not
		}
	while(flag != 'n' || flag != 'N');
	
	cout <<"\n\nAll done. Bye";
	return 0;

Wheres the closing brace for your main function?

for (i=1;i<=blankCount; i++){
			cout <<"  \t";
		}
		for(i=1; i <= totalDates; i++){
			cout << i << "\t";
			dayCount++;
			if (dayCount==7){
				cout << "\n";
				dayCount=0;}
		}

Ok... so for instance April... the output looks like this:

I will display the calendar for the month you choose in 2008.

please input the month you wish to see corisponding with its number.
4
April2008
Sun	Mon	Tues	Wed	Thurs	Fri	Sat
===	===	===	===	===	===	===
  	  	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	
Do you wish to see another month? Y/N or y/n?

Here's what your code is doing:

for (i=1;i<=blankCount; i++){  // blankCount for April
	cout <<"  \t";             // is 2, print 2 blanks
}
for(i=1; i <= totalDates; i++){  // from 1 to 7, dayCount
	cout << i << "\t";           //  incremented, but does
	dayCount++;                  //   not take into account 
	if (dayCount==7){            //  value of blankCount
		cout << "\n";
		dayCount=0;}
}

You need to give the value of blankCount to dayCount+1 before getting to this section in your code, then, the dayCount will begin at 2, rather than 0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.