I make this for balancing paranthesis of equation but i think it is wrong check and c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muhammadlodhi
    New Member
    • Apr 2010
    • 7

    I make this for balancing paranthesis of equation but i think it is wrong check and c

    Code:
    int main(){
    char i,input[30],close,open;
    for(i=0;i<='.';i++){
    printf("enter equation");
    scanf("%c",input[i]);
    if(input[i]=='(')
    input++;
    input[i]=open;
    else if(input[i]==')')
    input[i]--;
    input[i]=close;
    else if(open[i]==close[i])
    {
    printf("paranthesis are balance");
    }
    else
    printf("paranthesis are not balance");
    }
    
    getch();
    return 0;
    
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You have to use braces with your if statements. This code:

    Code:
    if(input[i]=='(') 
    input++;
    is a complete iof statement. It cannot have an else. You need to:

    Code:
    if(input[i]=='(') 
    {
    input++; 
    etc...
    
    }
    else
    {
    
    }
    BTW: There is also an input++. This is bad because input is a local array and you cannot change the address of a local variable.

    Comment

    • muhammadlodhi
      New Member
      • Apr 2010
      • 7

      #3
      so what is the solution.?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Read my post again.

        Put braces in your if statements.

        Comment

        • muhammadlodhi
          New Member
          • Apr 2010
          • 7

          #5
          but it is not given me the output which i want

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Does your current code compile with no errors or warnings? The code you've posted has errors.

            Comment

            • muhammadlodhi
              New Member
              • Apr 2010
              • 7

              #7
              yeah i do but with error and many warning plz u can edit this plz do it thanks

              Comment

              • jkmyoung
                Recognized Expert Top Contributor
                • Mar 2006
                • 2057

                #8
                If this program doesn't work, try making a simpler one. Save this file and start a new file.
                Eg, try making a program that counts open and close parentheses and checks if they are equal first.

                If you're trying to jump up 4 steps at a time, of course you're going to fall, but that doesn't mean we'll carry you up the stairs. Take it 1 step at a time.
                Last edited by jkmyoung; Apr 16 '10, 05:13 PM. Reason: calmed down

                Comment

                Working...