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.
Count the opening bracket and decrease this positive or null number with each closing bracket !
Last edited by 007Julien; 05-11-2013 at 11:52 AM.
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,
would be acceptable, but
would be unacceptable.
You might find some good sources online. See http://mathjs.org/ for an example.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)