Thread: truth table, inputting values, determine true or false, show values on truth tables,

  1. #1
    Registered User
    Join Date
    May 2014
    Posts
    23

    truth table, inputting values, determine true or false, show values on truth tables,

    hello

    im stuck on this problem.

    A truth table shows the results of values when combined in certain ways.write a program to show truth tables for combining true and false values using the and operator and or operator. print out the results as the values of the "and" or, "or" exspression (0 or 1)

    variables
    T variable with true value
    F variable with false value

    execution

    AND Truth Table OR Truth Table
    T F T F
    T 1 0 T 1 1
    F 0 0 F 1 0

    I have no idea as how to do this. I started by defining the T and F values as 1 and 0 respectively.
    problem is I have to use logical operators and I think if statements. the chapter im reading at the moment is about if, if else, switch, break and logical operators and expressions.
    so I think I would have to scanf something, then compare/test it using && for AND table. it shows two T in AND table. so....
    if(T ==1 && F == 1)

    im not sure how to do this. I know that for AND to work it would require two of the same thing. the false is both zero, is this not two of the same thing?
    I think the problem is getting truth tables right. but the programming part is still causing me the most problems
    if anyone has a starting point, beside "go learn truth tables, then go learn C", I would really appreciate it.

    thanks
    simon

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I started by defining the T and F values as 1 and 0 respectively.
    Sounds like a good start.

    problem is I have to use logical operators and I think if statements.
    You might be over-thinking this - you don't necessarily need "if()" statements.

    Consider this simple example:

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        printf("%d, %d\n",0&&1,1&&1);
    
        return 0;
    }
    It's not exactly what you need, but should illustrate how can approach solving the problem.

    so I think I would have to scanf something, then compare/test it using && for AND table.
    The assignment, as you stated, requires you to print out a table. I don't see any need to get user input, based on what you've provided.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Truth Table
    By Lycan in forum C Programming
    Replies: 6
    Last Post: 06-02-2012, 09:30 AM
  2. truth table
    By sagittarius83 in forum C Programming
    Replies: 15
    Last Post: 10-30-2010, 02:02 PM
  3. Truth tables and binary
    By AmbliKai in forum C Programming
    Replies: 5
    Last Post: 08-29-2008, 07:10 AM
  4. XOR truth table
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2006, 10:12 AM
  5. Programming a Truth Table
    By Nitelite in forum C Programming
    Replies: 2
    Last Post: 09-26-2002, 01:49 PM