Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6582901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:20:22+00:00 2026-05-25T16:20:22+00:00

I wrote the following code to judge whether an expression entered by user has

  • 0

I wrote the following code to judge whether an expression entered by user has correct sequence of brackets or not, e.g. if user enters [a*(b+c)] its ok. But if he enters [a*(b+c)[ its not correct.

Stacklist.cpp is a file which contains the linked list implementation of stacks and definitions of functions of push and pop. Display is the function which just shows the top entry.

#include<iostream>
#include<exception>
using namespace std;
#include"stacklist.cpp"

int main()
{
string s;
cin>>s;//user inputs the string
stacklist<int> stack1;//the class in stacklist.cpp...int because all bracket's ascii values are ints
char c;

while((c=cin.get())!=EOF)
{

   switch('c')
   {
       case '(': case '{': case '[':
           stack1.push('c');
           break;

       case ')':
           {char s=stack1.display();
              try
              {
                if(s=='(')
                  { stack1.pop();
                   continue;}
                else
                  throw 5;
              }//try block    

              catch(5) //.......(a)
              {
              cout<<"unmatched bracket error";
              exit(-1);
              }//catch over    
           }//')' case 
           break;

        case '}': //.......(b)
           {char s=stack1.display();
              try
               {
               if(s=='{')
                  { stack1.pop();
                  continue;}
               else
                  throw 6;
               }//try block    

              catch(6) //......(a)
               {
                cout<<"unmatched bracket error";
                exit(-1);
               }//catch over    
           }//'}' case
           break;

         case ']': ........(c)
           {char s=stack1.display();
             try
              {
               if(s==']')
                  { stack1.pop();
                  continue;}
               else
                  throw 7;
              }//try block    

             catch(7) //.............(a)
              {
              cout<<"unmatched bracket error";
              exit(-1);
              }//catch over    
           }//']' case  
           break;//..........(d)

         default:
             break;     
    }   //switch 

} //while  

 if(stack1.display==0)//0 is displayed if stack is empty
    cout<<"string is correct"<<endl;
 else
    cout<<"unequal number of brackets"<<endl;

  system("pause"); //........(e)
  return 0; 
}    //main

Now the problem is that when I compiled the code there were various errors:

syntax error before numeric constant.........in all (a)
case label '}' not within switch statement........(b)
case label ']' not within switch statement........(c)
syntax error before break.................(d)
ISO forbids declaration of 'system' with no type...........(e)

Please tell me how to plug these errors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:20:22+00:00Added an answer on May 25, 2026 at 4:20 pm
    • system is found in the header cstdio, but you did not #include that header.

      Anyway, it’s best not to use “tricks” like system("pause") to keep the console window after your program ends: if your console environment is not hanging around after your program has finished doing its meaningful work, then that’s your console environment’s fault/problem and you should configure it properly so that that does not happen. Pausing is not part of your program’s job.

    • Catching looks like this:

      catch (Type object-name) { code }
      

      object-name is optional, but Type is not.

      Therefore catch (6) is ill-formed. The other errors are a result of this one: parsing of your program goes all wonky when you write stuff that is not valid C++!

    And your indentation is pretty horrendous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wrote following code to create a linkbutton programmatically, but its showing like lable
if wrote the following code and do not understand why the trace returns false:
I wrote the following code for a Link list to create a Book its
I wrote the following code, but it does not work (It saves stupid things
I wrote the following code to change the user account and password associated with
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
In C++Builder, I wrote the following code (in Button1Click handler), When I run in
I'm working with the jQuery Validation plugin and I wrote the following code which
I needed some simple string encryption, so I wrote the following code (with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.