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

Username:   Password: 
 RegisterRegister   
 IF button problem.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
NEOS




PostPosted: Sun Nov 16, 2008 9:10 am   Post subject: IF button problem.

Turing:

loop
        % Gets ther cursor position.
        mousewhere (xmouse, ymouse, button)
        mouseshow
        locate (3, 16)
        put val1
        locate ()
        % If this area of the screen is clicked then the procedure buttons is shown.
        if xmouse >= 110 and xmouse <= 210 and ymouse >= 40 and ymouse <= 90 and button = 1 then
            locate (3, 16)

            val1 := 1
            put "1"
            val2 := 0
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 330 and xmouse <= 425 and ymouse >= 40 and ymouse <= 90 and button = 1 then
            locate (3, 26)
            val1 := 0
            put "0"
            val2 := 1
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 110 and xmouse <= 210 and ymouse >= 100 and ymouse <= 150 and button = 1 then
            locate (3, 20)
            put "AND"
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 110 and xmouse <= 210 and ymouse >= 170 and ymouse <= 220 and button = 1 then
            locate (3, 20)
            put "XOR"
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 225 and xmouse <= 320 and ymouse >= 100 and ymouse <= 150 and button = 1 then
            locate (3, 20)
            put "OR"
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 350 and xmouse <= 425 and ymouse >= 230 and ymouse <= 270 and button = 1 then
            drawfillbox (110, 290, 482, 375, 0)
            displayDraw
            calculatorDraw
            %
        elsif xmouse >= 225 and xmouse <= 320 and ymouse >= 40 and ymouse <= 90 and button = 1 then
            displayDraw
            calculatorDraw
        end if

    end loop


My problem is that I need the buttons to put 1 or 0 in the first area if pressed and if that happens then the next button that is pressed is put in the second area. (It's a calculator)
Sponsor
Sponsor
Sponsor
sponsor
DanielG




PostPosted: Sun Nov 16, 2008 11:11 am   Post subject: RE:IF button problem.

can you show all your code? it's impossible to run and see what you are trying to do
NEOS




PostPosted: Sun Nov 16, 2008 11:46 am   Post subject: Re: IF button problem.

Turing:

% Main Program

var xmouse, ymouse, button, a, b, c, d, e, f, g, h, val1, val2 : int

% This procedure will draw a button leading to the Logic Calculator.


procedure title
    % Draws boxes to animate "1 - 1 = 0"
    drawfillbox (100, 200, 120, 300, 1)
    drawfillbox (79, 200, 140, 180, 1)
    drawfillbox (79, 300, 120, 280, 1)
    drawfillbox (300, 200, 320, 300, 1)
    drawfillbox (279, 200, 340, 180, 1)
    drawfillbox (279, 300, 320, 280, 1)
    drawfillbox (170, 240, 240, 220, 16)
    drawfillbox (430, 230, 360, 210, 16)
    drawfillbox (430, 270, 360, 250, 16)
    drawfillbox (450, 300, 540, 180, 16)
    drawfillbox (520, 280, 470, 200, 0)
    % gets the cursor position
    mousewhere (xmouse, ymouse, button)
    % Writes text.
    locate (21, 1)
    put "My test numbers to prove my logic calculator  "
    put "ands two binary digits ors two binary digits negates"
    put "a binary digit will be 1 and 0, 1 representing high and"
    put "0 representing low. Click the button to see my Logic Calculator."
    % Draws button that leads to the Logic Calculator.
    locatexy (463, 64)
    put "LOGIC CALCULATOR"
    drawbox (450, 30, 600, 100, 16)
end title

% This draws the body of the calculator.
procedure calculatorDraw
    drawbox (90, 10, 500, 390, 4)
end calculatorDraw

% This procedure draws the answer-display area
procedure displayDraw
    drawbox (110, 290, 482, 375, 1)
end displayDraw


%
function ANDcalc (val1 : int, val2 : int) : int
    result val1 and val2
end ANDcalc


%
function OR (val1 : int, val2 : int) : int
    result val1 or val2
end OR


%
function NOT (val1 : int, val2 : int) : int
    result not val1
end NOT


%
function NAND (val1 : int, val2 : int) : int
    result not val1 and not val2
end NAND


%
function XOR (val1 : int, val2 : int) : int
    result val1 xor val2
end XOR



% This procedure draws buttons on the calculator.
procedure buttonDraw

    % Locates the text
    locate (21, 21)
    put "1"

    locate (21, 35)
    put "="

    locate (21, 47)
    put "0"

    locate (10, 47)
    put "CLEAR"

    locate (13, 20)
    put "XOR"

    locate (17, 21)
    put ""

    locate (13, 33)
    put ""

    locate (13, 48)
    put ""

    locate (17, 19)
    put "AND"


    locate (17, 34)
    put "OR"

    locate (17, 48)
    put ""

    displayDraw
    calculatorDraw

    % 1 button POSITION.
    drawbox (110, 40, 210, 90, 1)

    % 0 button POSITION.
    drawbox (330, 40, 425, 90, 1)

    % EQULAS button POSITION.
    drawbox (225, 40, 320, 90, 1)

    % CLEAR button POSITION.
    drawbox (350, 230, 425, 270, 4)

    %  button POSITION.
    drawbox (330, 100, 425, 150, 16)

    %  button POSITION.
    drawbox (225, 100, 320, 150, 16)

    %  button POSITION.
    drawbox (225, 170, 320, 220, 16)

    %  button POSITION.
    drawbox (330, 170, 425, 220, 16)

    %  button POSITION.
    drawbox (110, 170, 210, 220, 16)

    %  button POSITION.
    drawbox (110, 100, 210, 150, 16)

    % Values of the variables a and b.
    val1 := 0
    val2 := 0
    locate (3, 16)
    put val1
    locate (3, 26)
    put val2
    a := 1
    b := 0
    loop
        % Gets ther cursor position.
        mousewhere (xmouse, ymouse, button)
        mouseshow

        % If this area of the screen is clicked then the procedure buttons is shown.
        if xmouse >= 110 and xmouse <= 210 and ymouse >= 40 and ymouse <= 90 and button = 1 then
            locate (3, 16)
            put "1"

            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 330 and xmouse <= 425 and ymouse >= 40 and ymouse <= 90 and button = 1 then
            locate (3, 26)
            put "0"
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 110 and xmouse <= 210 and ymouse >= 100 and ymouse <= 150 and button = 1 then
            locate (3, 20)
            put "AND"
            ANDcalc (val1, val2)
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 110 and xmouse <= 210 and ymouse >= 170 and ymouse <= 220 and button = 1 then
            locate (3, 20)
            put "XOR"
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 225 and xmouse <= 320 and ymouse >= 100 and ymouse <= 150 and button = 1 then
            locate (3, 20)
            put "OR"
            calculatorDraw
            displayDraw
            %
        elsif xmouse >= 350 and xmouse <= 425 and ymouse >= 230 and ymouse <= 270 and button = 1 then
            drawfillbox (110, 290, 482, 375, 0)
            displayDraw
            calculatorDraw
            %
        elsif xmouse >= 225 and xmouse <= 320 and ymouse >= 40 and ymouse <= 90 and button = 1 then
            displayDraw
            calculatorDraw
        end if

    end loop
    %
end buttonDraw
%
% ------------------------------------------------------------ MAIN LINE ------------------------------------------------------------ %

title
loop
    % Gets ther cursor position.
    mousewhere (xmouse, ymouse, button)
    mouseshow
    % If this area of the screen is clicked then the procedure buttons is shown.
    if xmouse >= 450 and xmouse <= 600 and ymouse >= 30 and ymouse <= 100 and button = 1 then
        cls
        calculatorDraw
        displayDraw
        buttonDraw
    end if
end loop
pavol




PostPosted: Sun Nov 16, 2008 12:50 pm   Post subject: RE:IF button problem.

well, your code doesn't even compile because of
ANDcalc (val1, val2)
that line. You have declared your function as returning an int but in that line you call it as if it did not return anything. Since ANDcalc() returns a value you need to set it to something like
intVariable = ANDcalc(val1, val2)
NEOS




PostPosted: Sun Nov 16, 2008 1:14 pm   Post subject: Re: IF button problem.

Sorry I didn't understand what you just said!
andrew.




PostPosted: Sun Nov 16, 2008 2:14 pm   Post subject: RE:IF button problem.

Your function ANDCalc returns an integer. But you are calling it like a procedure so it can't return anything so it gives you an error.

You used:
Turing:
ANDCalc (val1, val2)


But that gives an error because there is nowhere to put the value that is returned. You have to do something like this:
Turing:
put ANDCalc (val1, val2)


Functions always return a value and that value always has to be stored somewhere either in a variable or using it right away (put ANDCalc (val1, val2)).
NEOS




PostPosted: Sun Nov 16, 2008 2:49 pm   Post subject: Re: IF button problem.

ok that answers that but my original question wasn't answered. I want it to, when, the user presses a button, 1 or 0, it puts it in a certain area then when they press a second button, 1 or 0, it will put it in the second area. I've tried but the 0 would just disappear....
pavol




PostPosted: Sun Nov 16, 2008 10:51 pm   Post subject: Re: IF button problem.

I apologize ahead of time for nagging you about this again...but your code doesn't compile! The problem I stated earlier prevents you from running the program, so I have no clue how you even test your program if it doesn't run...?
So assuming I remove that one line that is causing the problem and run your program again, there's a couple of things: your program doesn't actually do any logical testing yet, although I'm sure you're already aware of this. Next, for your problem about the 1's and 0's, you have designated the position of (3, 16) to 1 and the position (3, 26) to 0, this means that the only combination of 1 and 0 that I press which will show up on the screen is 1 followed by 0. This is because when you press 1, it will put it in position 16, then you chose your test, which will be displayed in position 20, and finally 0 will be put in position 26. Lets say I try the combination of 0-1 instead. Fist my 0 gets put in position 26, then the logical test gets put into position 20...overwriting what was in position 26, and finally when I put 1, it will be in position 16, overwriting everything else. Therefore, you need to adapt your code for what happens when 1 and 0 is pressed so that they can put 1 or 0 in the position given by both (3, 16) and (3, 20). This can be simply accomplished by the addition of a boolean variable.
Ex/
Turing:
var pos16 : boolean := false    %Evals to true if position (3, 16) is taken, and false if it is not
if xmouse >= 110 and xmouse <= 210 and ymouse >= 40 and ymouse <= 90 and button = 1 then
    if pos16 = false then
        locate (3, 16)
        pos16 := true
    else
        locate (3, 26)
    end if

    put "1"
end if

You can then similarly adapt your code for the 0 button, etc.
I hope this helps a bit more.
Sponsor
Sponsor
Sponsor
sponsor
NEOS




PostPosted: Mon Nov 17, 2008 12:41 pm   Post subject: Re: IF button problem.

Where do I put it?
NEOS




PostPosted: Wed Nov 19, 2008 1:01 pm   Post subject: RE:IF button problem.

Bump
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  [ 10 Posts ]
Jump to:   


Style:  
Search: