www.webdeveloper.com
Results 1 to 3 of 3

Thread: Matching Parenthesis

Hybrid View

  1. #1
    Join Date
    May 2013
    Posts
    1

    Matching Parenthesis

    Hello, all.
    I thought making a calculator would be a fairly simple practice exercise, but it's turning out more complicated than I had anticipated.
    I don't want the user to be able to type a closing bracket if there isn't a matching opening bracket. I know how to search the string for specific characters, but I'm having trouble figuring out how to determine if there is an open parenthesis that needs to be closed.
    Basically I want "(3+5)" to be possible, but "3+5)" to be impossible to type.

    Thanks,
    Teru

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Count the opening bracket and decrease this positive or null number with each closing bracket !
    Last edited by 007Julien; 05-11-2013 at 10:52 AM.

  3. #3
    Join Date
    Mar 2011
    Posts
    1,141
    You're going to have to count the number of left and right parenthesis in the user's entry and see if they match. On a good day, you'll also check to see that they're in an acceptable order. That is,
    Code:
    (a + (b*c))
    would be acceptable, but
    Code:
    )a + (b*c)(
    would be unacceptable.

    You might find some good sources online. See http://mathjs.org/ for an example.
    Rick Trethewey
    Rainbo Design

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles