Thread: Programming a Truth Table

  1. #1
    Registered User
    Join Date
    Sep 2002

    Programming a Truth Table

    I am trying to create a program that prompts the user to input 2 Equations, do a truth table, then compare them. Most of it is within my ability, but what I am struggling with is the parsing of the inputted equations. For example:

    F1 = !A * !B + A * B + !A * B F2 = !A + B

    For something like this, I just made a char pointer that scans through the string looking for multiplication, doing that first, then the addition. My problem is parsing and getting the order of operations down for something like this:

    F1 = !A * B (!C * !A * C) + B (A + !A * C)
    F2 = !((A + !B*!C + C) * ( B * C + !A + A * !B * !C))

    So how would you parse something with parenthensis. Not necessarily asking for help with code, more theory in breaking this down into proper operational order.

    Thanks guys

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Simple. Everytime you encounter an open parantheses '(' simply keep track of where you are parsing. Then when you encounter a closed parantheses ')', calculate your logic up to the previous '(' and treat the problem as you would in your 1st example.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Recursion. Any time you see an opening parenthesis, make a recursive call. Any time you see a closing parenthesis, make a return call. Otherwise, loop using standard mathmatics.

    [edit]Damnit! Stop beating me to the reply! [/edit]

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  2. XOR truth table
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2006, 10:12 AM
  3. program to construct a truth table
    By ashok varma in forum C Programming
    Replies: 2
    Last Post: 08-04-2005, 10:53 AM
  4. logic circuit truth table
    By botakis in forum C Programming
    Replies: 3
    Last Post: 11-18-2004, 11:02 AM
  5. exercise clarification truth table
    By curlious in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2003, 07:28 PM