Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help making a Truth Table using Turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Bucket




PostPosted: Fri Mar 18, 2011 9:57 pm   Post subject: Need help making a Truth Table using Turing

What is it you are trying to achieve?
I'm trying to create a truth table that uses 5 variables and the AND, OR, NOT, XOR expressions.


What is the problem you are having?
Confused about what to write.


Describe what you have tried to solve this problem
I tried using the if, then, and or statements but I can't seem to get it right.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


setscreen ("text")

var a : boolean
var b : boolean
var c : boolean
var d : boolean
var e : boolean

put "  A" : 10, "  B" : 10, "  C" : 10, "  D" : 10, "  E" : 10, "  Output" : 10

for countera : 0 .. 1
    for coutnerb : 0 .. 1
        for counterc : 0 .. 1
            for counterd : 0 .. 1
                for countere : 0 .. 1



This is all I have which isn't really anything. x.x

 


Please specify what version of Turing you are using
Currently using version 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Fri Mar 18, 2011 11:14 pm   Post subject: RE:Need help making a Truth Table using Turing

How would you do just one case here?

A and B or C not D xor E = ?

We here have 5 variables? or is it just that? We have 5 boolean variables, but we also have 4 operators that are variable as well. All in all, 9 variables.

Lets just focus on a situation of 2 booleans, and one operator.

You can't exactly pass operators as a variable though, as there is no operator data type that could be used to store in a variable.

Instead, we'll use constants to represent them.

const op_or := 0
const op_and := 1


You could use an enum (enumerated type) to simplify this, however it becomes more complex and annoying in turing with enums and loops.

Then you could use a case selection (or a bunch of ifs) to actually get the result of what that operator did to the booleans. If I were me, I'd put this in it's own function, as this code will be used alot.

Turing:

case (op1):
    label op_or:
        put x or y
end case


After that, you'll be stacking up those for loops for each value of a, b, and the operator.

Then you'll have a two variable truth table!

For more than two variables, you have to assume that you first need to know the result of the first two, then compare that result to the third, then compare that ... and so on.

fn(fn(a, op1, b), op2, c)
Tony




PostPosted: Fri Mar 18, 2011 11:18 pm   Post subject: RE:Need help making a Truth Table using Turing

Quote:
AND, OR, NOT, XOR

All of those operators work on two arguments, not five.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Prince Pwn




PostPosted: Sun Mar 20, 2011 1:06 am   Post subject: RE:Need help making a Truth Table using Turing

First off it looks like he is looking for help with his homework. It doesn't seem like he knows about cases or labels yet so let's not jump too far ahead Very Happy

Start off by ending your end fors. Then inside your nested for loop, use if statments comparing the for loop variables using the expressions and, or, not, xor.

An if statement looks as follows:

code:

if 5 < x then
   put "1 is less than your variable"
end if


Place that block into a for loop that counts from 1 to 10 and look at the results. Then you should understand how a for loop works.

Now apply the for loop and if statements with what you know about truth tables and it should become clear to you on how to go about solving the problem at hand.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: