236.cpp(41): this line contains a '{' which has not yet been matched

THE CODING IS:

#include<iostream>
#include<string>
#include<conio.h>
#include<IOMANIP>
#include<fstream>
//#include<cctype> //for toupper function


using namespace std;

class TESTstudent 

{
  string name[3];
  string sir_name[3];
  int roll_no[3];
  int count;
 // FOR LIBRARY
  string book1[3];
  string book2[3];
  int dues[3];
  int num_book[3];
  int count_lib;

public:
    void TESTset_count()
        {count=0; count_lib=0;}
    //void TESTenroll();
    //void TESTsearch_record();
    //void TESTedit_record();//
    //void TESTdisplay2();
    void TESTlibrary();
    //void TESTlibrary_status();
}; // CLASS ENDS

//LIBRARY FUNCTION//

void TESTstudent::TESTlibrary()

[B]
{
[/B]    
 [U][B]GIVES THE ERROR ON THIS '{'.HOW SHOULD I RESOLVE THIS?[/B][/U]

if(count<1)
 {cout<<"LIBRARY CAN NOT BE ACCESSED AS NO RECORD EXIST"<<endl; return;}
int temp, check=0;
cout<<"ENTER THE ROLL NUMBER.THE ROLL NUMBER SHOULD NOT BE GREATER THAN 100 OR LESSER THAN ONE.."<<endl;
cin>>temp;
{
if( temp<1&&temp>100 )
cout<<"ERROR! you have not entered an integet.Please enter an integer! "<< endl;
}

for(int i=0;i<count;i++)
{if(temp==roll_no[i])
 {if(dues[i]==1)
   {cout<<"BOOKS ARE ALREADY ISSUED ON THIS ROLL NUMBER, SORRY"<<endl; return;}
 }
}
for(int i=0;i<count;i++)
{if(temp==roll_no[i])
  { check=1;
   {H2:
     cout<<"ENTER THE NUMBER OF BOOKS THAT YOU WANT TO ISSUE(1/2)?"<<endl;
     cin>>num_book[i];
     switch(num_book[i])
     {
     case 1:
       {cout<<"ENTER THE NAME OF BOOK"<<endl;
        getline(cin,book1[i],'$');
        {
//{ if(!((book1[i]>='A'&&book1[i]<='Z')||(book1[i]>='a'&&book1[i]<='z') ) )
            // cout<<"Please enter alphabets!"<<endl; }}
            dues[i]=1;
        ++count_lib;
        goto F2;
        break;
       }
     case 2: 
     {cout<<"ENTER THE NAME OF BOOK 1"<<endl;
      getline(cin,book1[i],'$');
      cout<<"ENTER THE NAME OF BOOK 2"<<endl;
      getline(cin,book2[i],'$');
      dues[i]=1;
      ++count_lib;
      goto F2;
      break;
     }
     default:
         {cout<<"YOU CAN NOT ISSUE MORE THAN 2 BOOKS"<<endl; goto H2; break;}
     }
   }
}
}
F2:
 if(check==0)
 {cout<<"INVALID ROLL NUMBER"<<endl;};
}
  ///////////////////////

int main()
{
TESTstudent Tst;
Tst.TESTset_count();
//Tst.TESTenroll();
//Tst.TESTsearch_record();
Tst.TESTlibrary();
system("pause");
return 0;
}// main ends here

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Well, your code as posted is not readable. So, you can start by re-posting your code within [code] ...code blocks... [/code] to make it readable.

The error means that you are most likely missing a '}' somewhere after that point.

#include<iostream>
#include<string>
#include<conio.h>
#include<IOMANIP>
#include<fstream>
//#include<cctype> //for toupper function


using namespace std;

class TESTstudent 

{
  string name[3];
  string sir_name[3];
  int roll_no[3];
  int count;
 // FOR LIBRARY
  string book1[3];
  string book2[3];
  int dues[3];
  int num_book[3];
  int count_lib;
  
public:
    void TESTset_count()
        {count=0; count_lib=0;}
	void TESTenroll();
	void TESTsearch_record();
	//void TESTedit_record();//
	void TESTdisplay2();
	void TESTlibrary();
	void TESTlibrary_status();
}; // CLASS ENDS

//LIBRARY FUNCTION//

void TESTstudent::TESTlibrary()

{

if(count<1)
     {cout<<"LIBRARY CAN NOT BE ACCESSED AS NO RECORD EXIST"<<endl; return;}
int temp, check=0;
cout<<"ENTER THE ROLL NUMBER.THE ROLL NUMBER SHOULD NOT BE GREATER THAN 100 OR LESSER THAN ONE.."<<endl;
cin>>temp;
{
if( temp<1&&temp>100 )
{cout<<"ERROR! you have not entered an integer.Please enter an integer! "<< endl;}
}//this if ends

for(int i=0;i<count;i++)
{if(temp==roll_no[i])
 {if(dues[i]==1)
   {cout<<"BOOKS ARE ALREADY ISSUED ON THIS ROLL NUMBER, SORRY"<<endl; return;}
 }//nested if ends
}//pre if ends
for(int i=0;i<count;i++)
{if(temp==roll_no[i])
  { check=1;
   {H2:
	 cout<<"ENTER THE NUMBER OF BOOKS THAT YOU WANT TO ISSUE(1/2)?"<<endl;
	 cin>>num_book[i];
	 switch(num_book[i])
	 {
	 case 1:
	   {cout<<"ENTER THE NAME OF BOOK"<<endl;
	    getline(cin,book1[i],'$');
		{
//{ if(!((book1[i]>='A'&&book1[i]<='Z')||(book1[i]>='a'&&book1[i]<='z') ) )
            // cout<<"Please enter alphabets!"<<endl; }}
			dues[i]=1;
		++count_lib;
		goto F2;
		break;
	   }
	 case 2: 
	 {cout<<"ENTER THE NAME OF BOOK 1"<<endl;
	  getline(cin,book1[i],'$');
      cout<<"ENTER THE NAME OF BOOK 2"<<endl;
	  getline(cin,book2[i],'$');
	  dues[i]=1;
	  ++count_lib;
	  goto F2;
	  break;
	 }
	 default:
		 {cout<<"YOU CAN NOT ISSUE MORE THAN 2 BOOKS"<<endl; goto H2; break;}
	 }
   }
   }
}
F2:
 if(check==0)
 {cout<<"INVALID ROLL NUMBER"<<endl;};
}
  ///////////////////////

int main()
{
TESTstudent Tst;
Tst.TESTset_count();
//Tst.TESTenroll();
//Tst.TESTsearch_record();
Tst.TESTlibrary();
system("pause");
return 0;
}// main ends here
46. cin>>temp;
47. {
48. if( temp<1&&temp>100 )
49. {cout<<"ERROR! you have not entered an integer.Please enter an integer! "<< endl;}
50. }//this if ends

Are you sure you have your braces correctly paired here? The brace on Line 50 closes the block opened on Line 47, not your if statement; the if ends on Line 49. Have another look (reformatted for readability):

cin >> temp;
{
  if (temp < 1 && temp > 100) {
    cout << "ERROR! you have not entered an integer.Please enter an integer! "<< endl;
  }
}//this if ends

There are several such examples throughout that function's implementation... I would also suggest you do better about your indentation. The top part of your code isn't too bad, but the bottom is awful. It almost looks like it was written by 2 different people...

Using braces is a good idea, but I think you need to position them better:

52. for(int i=0;i<count;i++)
53. {if(temp==roll_no[i])
54.  {if(dues[i]==1)
55.    {cout<<"BOOKS ARE ALREADY ISSUED ON THIS ROLL NUMBER, SORRY"<<endl; return;}
56.  }//nested if ends
57. }//pre if ends

there are 2 common schools of though on placement, I prefer this way:

for (int i = 0; i < count; ++i) {
  if (temp == roll_no[i]) {
    if(dues[i] == 1) {
      cout << "BOOKS ARE ALREADY ISSUED ON THIS ROLL NUMBER, SORRY" << endl;   return;
    } //end dues if
  } //end temp if
} //end for

but others prefer this way instead:

for (int i = 0; i < count; ++i)
{
  if (temp == roll_no[i])
  {
    if(dues[i] == 1)
    {
      cout << "BOOKS ARE ALREADY ISSUED ON THIS ROLL NUMBER, SORRY" << endl;   return;
    } //end dues if
  } //end temp if
} //end for

Notice how much easier they make it to see them?

Edited 5 Years Ago by Fbody: n/a

Well look, there is a '{' that opens before if and then it gets closed too.
Similarly, there is a '{' that opens for cout and then it gets closed after endl.How is it wrong?

The opening brace on line 67 isn't properly closed before the next case. This is what happens when you have a piss poor bracing style. :icon_rolleyes:

This article has been dead for over six months. Start a new discussion instead.