Computer Science Canada Urgent Turing Calculator Help |
Author: | Wajih [ Tue Jan 11, 2011 5:30 pm ] | ||
Post subject: | Urgent Turing Calculator Help | ||
What is it you are trying to achieve? i am trying to make a visual calculator that if a person clicks a number, the number should go to the screen and display the number. the same thing with the second number and the symbol. but i cannot do it. What is the problem you are having? i do not know how to make the mouse recognize i clicked the number/symbol Describe what you have tried to solve this problem i have tried looping it. making new variables, etc but it will still not work. the thing i want to find out is how will the mouse recognize if clicked the number and/ or symbol. and how to display it on the screen. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) var num : real var num2 : real var symbol : string drawbox (100, 100, 500, 475, red) drawbox (128, 305, 470, 350, black) locate (2, 32) put "CALCULATOR" .. locate (16, 19) put "1" .. locate (16, 26) put "2" .. locate (16, 33) put "3" .. locate (13, 19) put "4" .. locate (13, 26) put "5" .. locate (13, 33) put "6" .. locate (10, 19) put "7" .. locate (10, 26) put "8" .. locate (10, 33) put "9" .. locate (10, 40) put "=" .. locate (16, 40) put "-" .. locate (13, 40) put "+" .. locate (13, 45) put "/" .. locate (13, 50) put "*" .. drawoval (148, 151, 12, 12, black) drawoval (205, 151, 12, 12, black) drawoval (262, 151, 12, 12, black) drawoval (148, 200, 12, 12, black) drawoval (205, 200, 12, 12, black) drawoval (262, 200, 12, 12, black) drawoval (148, 249, 12, 12, black) drawoval (205, 249, 12, 12, black) drawoval (262, 249, 12, 12, black) drawoval (316, 249, 20, 20, black) drawoval (316, 200, 13, 13, black) drawoval (316, 151, 13, 13, black) drawoval (356, 200, 13, 13, black) drawoval (396, 200, 13, 13, black) drawfillbox (280, 100, 290, 300, black) locate (20, 1) put "please enter your first number : " .. get num locate (5, 20) get num locate (22, 1) put "please enter your symbol" get symbol locate (5, 25) get symbol locate (24, 1) put "please enter your second number" get num2 locate (4, 30) get num2
Please specify what version of Turing you are using 4.1.1 |
Author: | TerranceN [ Tue Jan 11, 2011 6:05 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
Well you can get the mouse co-ordinates using <a href="http://compsci.ca/holtsoft/doc/mouse_where.html">Mouse.Where</a>, and then detect if the mouse position is in each of the buttons. You can find out how to do that with a <a href="http://www.google.ca/search?q=how+to+tell+if+a+point+is+in+a+circle">quick google search</a>. |
Author: | Wajih [ Tue Jan 11, 2011 6:15 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
i still dont get how to do that thoug. do you have to use the variables that are already there or do you have to create new ones? |
Author: | TokenHerbz [ Tue Jan 11, 2011 8:07 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
you have to declare variable to use in turing, so... var mx, my, mb: int for like mouse x,y button inside your loop to use it, Mouse.Where(mx,my,mb) to use these vars for mouse then like, mx,my are chords of your mouse mb would be your button, like if mb = 1 then ***its clicked*** you can use more buttons to like middle/right but lets start wit hthis first |
Author: | Wajih [ Tue Jan 11, 2011 8:46 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
so how will that help the mouse trecognize thw number? can someone give me an example code so i can better understand this problem? help is appreciated |
Author: | Tony [ Tue Jan 11, 2011 9:09 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
That will just tell you that a mouse has been clicked... somewhere. You can use that location to figure out if it's been inside any of the button locations. If so, you get a value associated with that location. |
Author: | Wajih [ Tue Jan 11, 2011 9:37 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
but do i need to create new variables to use mousewhere command? or can i use the ones that i already have? |
Author: | Tony [ Tue Jan 11, 2011 9:40 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
What kind of variables does the documentation say that you need? And what kind of variables do you already have? |
Author: | Wajih [ Tue Jan 11, 2011 9:42 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
it says i need x and y and b, but i do not know what those are for. or how to use them in my physical code. the variables that i have so far are num, num2, symbol, and sum |
Author: | Tony [ Tue Jan 11, 2011 9:59 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
I think you might need those variables then. If you read Mouse.Where, it explains what all of them are for: Quote: The parameters x and y are set to the current location of the mouse cursor. Quote: button is set to 0 if all the mouse buttons are up, and 1 if any of the mouse buttons are down. |
Author: | Wajih [ Tue Jan 11, 2011 10:07 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
but what do x and y control, like how do they affect the mouse cursor and what happens if the mouse cursor hits any of the numbers and/or symbols. also what is the button needed for and what does ot mean that it is set to 0 or 1? |
Author: | TerranceN [ Tue Jan 11, 2011 10:14 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
The whole point of Mouse.Where is to find the position of the mouse. When you call Mouse.Where, it changes the values of the variables you send it to be the current state of the mouse (the mouse's x, y, and button). Once we know the position of the mouse, we can check if the button is down with an if statement. If it is down, we then need to check if it is inside a button. Since the buttons are circular, if the distance from the centre of the circle to the mouse is less then the radius of the circle (you set both of those when you drew the circle, so you know both of them), then the mouse is inside the circle. Since the button is down and the mouse is inside the circle, the button has been pressed. |
Author: | Tony [ Tue Jan 11, 2011 10:14 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
Please just read the linked docs. |
Author: | Wajih [ Tue Jan 11, 2011 10:54 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
i used the code. but it deleted the picture of my calculator. any reasons why? |
Author: | TerranceN [ Tue Jan 11, 2011 11:14 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
And how exactly did you use the code? Did you go through it and understand how and why it worked the way it does on its own, then apply the concepts it demonstrated to your own project? Or did you copy and paste it at the top of your own code? But considering the problem you are having, I am guessing the latter. If my guess is correct, the best advice I can give you is to actually learn Turing instead of copying and pasting code and hoping it will work. By the way, we have a nice Turing tutorial <a href="http://compsci.ca/v3/viewtopic.php?t=8808">here</a>. Although if I am wrong, my apologies for raging about kids who refuse to actually do work and/or think. |
Author: | Wajih [ Tue Jan 11, 2011 11:26 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
i read it and somewhat understand it now. i amstill trying to comprehend it some parts. i put my code inside the loop with the mousewhere and got the desired effect. the only thing now is how do you make the make the turing machine recognize what kind of number the mouse is at. and how to display it on the screen. if (x >= 196) and (x < 210) and (y > 237) and (y < 259) then put "8" end if i tried that. but it still does not show the answer in the box at the top. also how do i store the number. like for example say if the user enters a number, i want the number to be stored. do i have to put the num after the "8" or something like that |
Author: | Tony [ Tue Jan 11, 2011 11:33 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
You would probably want to put that number into some kind of a variable; then you could work with the values in your variables. |
Author: | Wajih [ Tue Jan 11, 2011 11:50 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
see i did that. i put it into the num variable which is a real. but it still says "8 false" if (button = 1) and( x >= 196) and (x < 210) and (y > 237) and (y < 259) then locate ( 5, 19) put "", 8, (num = 8) end if do you have any idea why it says false |
Author: | Tony [ Tue Jan 11, 2011 11:55 pm ] | ||
Post subject: | RE:Urgent Turing Calculator Help | ||
what is the value of num at that point?
What is the difference between real and int? |
Author: | Wajih [ Wed Jan 12, 2011 5:34 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
isnt int any whole number? and real is any number, either a whole number or decimal |
Author: | 2goto1 [ Wed Jan 12, 2011 5:53 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
An integer can be either positive or negative, whereas a whole number is 0 or greater. |
Author: | Wajih [ Wed Jan 12, 2011 6:26 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
i made the necessary corrections to the code. now the thing is how do i make the numbers for num 2 appear because every time i hit a number it only goes to num. does anyone know why? var num : real var num2 : real := 0 var symbol : string var x , y , button : int := 0 loop Mouse.Where (x, y, button) Text.Locate (22, 1) if button = 0 then put x : 0, " ", y : 0, " button up" else put x : 0, " ", y : 0, " button down" end if if (button = 1) and ( x >= 137) and ( x <= 158) and ( y >= 142) and ( y <= 163) then locate (5, 19) num := 1 put "", num end if if ( button = 1 ) and ( x >= 194) and (x <= 214) and ( y >= 142) and ( y <= 163) then locate (5, 19) num := 2 put "", num end if if ( button = 1 ) and ( x >= 251) and (x <= 272) and ( y >= 142) and ( y <= 163) then locate (5, 19) num := 3 put "", num end if if ( button = 1 ) and ( x >= 137) and (x <= 158) and ( y >= 190) and ( y <= 208) then locate (5, 19) num := 4 put "", num end if if ( button = 1 ) and ( x >= 194) and (x <= 214) and ( y >= 190) and ( y <= 208) then locate (5, 19) num := 5 put "", num end if if ( button = 1 ) and ( x >= 251) and (x <= 272) and ( y >= 190) and ( y <= 208) then locate (5, 19) num := 6 put "", num end if if ( button = 1 ) and ( x >= 137) and (x <= 158) and ( y >= 241) and ( y <= 258) then locate (5, 19) num := 7 put "", num end if if (button = 1) and( x >= 196) and (x < 210) and (y > 237) and (y < 259) then locate (5, 19) num := 8 put "", num end if if ( button = 1 ) and ( x >= 251) and (x <= 272) and ( y >= 241) and ( y <= 258) then locate (5, 19) num := 9 put "", num end if if (button = 1) and( x >= 298) and (x < 333) and (y > 234) and (y < 266) then locate (5, 30) symbol := "=" put "", symbol end if if (button = 1) and( x >= 387) and (x < 405) and (y > 190) and (y < 210) then locate (5, 22) symbol := "*" put "", symbol end if if (button = 1) and( x >= 345) and (x < 367) and (y > 188) and (y < 210) then locate (5, 22) symbol := "/" put "", symbol end if if (button = 1) and( x >= 305) and (x < 325) and (y > 142) and (y < 163) then locate (5, 22) symbol := "-" put "", symbol end if if (button = 1) and( x >= 305) and (x < 325) and (y > 190) and (y < 210) then locate (5, 22) symbol := "+" put "", symbol end if drawbox (100, 100, 500, 475, red) drawbox (128, 305, 470, 350, black) locate (2, 32) put "CALCULATOR" .. locate (16, 19) put "1" .. locate (16, 26) put "2" .. locate (16, 33) put "3" .. locate (13, 19) put "4" .. locate (13, 26) put "5" .. locate (13, 33) put "6" .. locate (10, 19) put "7" .. locate (10, 26) put "8" .. locate (10, 33) put "9" .. locate (10, 40) put "=" .. locate (16, 40) put "-" .. locate (13, 40) put "+" .. locate (13, 45) put "/" .. locate (13, 50) put "*" .. drawoval (148, 151, 12, 12, black) drawoval (205, 151, 12, 12, black) drawoval (262, 151, 12, 12, black) drawoval (148, 200, 12, 12, black) drawoval (205, 200, 12, 12, black) drawoval (262, 200, 12, 12, black) drawoval (148, 249, 12, 12, black) drawoval (205, 249, 12, 12, black) drawoval (262, 249, 12, 12, black) drawoval (316, 249, 20, 20, black) drawoval (316, 200, 13, 13, black) drawoval (316, 151, 13, 13, black) drawoval (356, 200, 13, 13, black) drawoval (396, 200, 13, 13, black) drawfillbox (285, 100, 286, 300, black) Mouse.Where (x, y, button) Text.Locate (22, 1) if button = 0 then put x : 0, " ", y : 0, " button up" else put x : 0, " ", y : 0, " button down" end if if (button = 1) and ( x >= 137) and ( x <= 158) and ( y >= 142) and ( y <= 163) then locate (5, 25) num2 := 1 put "", num2 end if if ( button = 1 ) and ( x >= 194) and (x <= 214) and ( y >= 142) and ( y <= 163) then locate (5, 25) num2 := 2 put "", num2 end if if ( button = 1 ) and ( x >= 251) and (x <= 272) and ( y >= 142) and ( y <= 163) then locate (5, 25) num2 := 3 put "", num2 end if if ( button = 1 ) and ( x >= 137) and (x <= 158) and ( y >= 190) and ( y <= 208) then locate (5, 25) num2 := 4 put "", num2 end if if ( button = 1 ) and ( x >= 194) and (x <= 214) and ( y >= 190) and ( y <= 208) then locate (5, 25) num2 := 5 put "", num2 end if if ( button = 1 ) and ( x >= 251) and (x <= 272) and ( y >= 190) and ( y <= 208) then locate (5, 25) num2 := 6 put "", num2 end if if ( button = 1 ) and ( x >= 137) and (x <= 158) and ( y >= 241) and ( y <= 258) then locate (5, 25) num2 := 7 put "", num2 end if if (button = 1) and( x >= 196) and (x < 210) and (y > 237) and (y < 259) then locate (5, 25) num2 := 8 put "", num2 end if if ( button = 1 ) and ( x >= 251) and (x <= 272) and ( y >= 241) and ( y <= 258) then locate (5, 25) num2 := 9 put "", num2 end if drawbox (100, 100, 500, 475, red) drawbox (128, 305, 470, 350, black) locate (2, 32) put "CALCULATOR" .. locate (16, 19) put "1" .. locate (16, 26) put "2" .. locate (16, 33) put "3" .. locate (13, 19) put "4" .. locate (13, 26) put "5" .. locate (13, 33) put "6" .. locate (10, 19) put "7" .. locate (10, 26) put "8" .. locate (10, 33) put "9" .. locate (10, 40) put "=" .. locate (16, 40) put "-" .. locate (13, 40) put "+" .. locate (13, 45) put "/" .. locate (13, 50) put "*" .. drawoval (148, 151, 12, 12, black) drawoval (205, 151, 12, 12, black) drawoval (262, 151, 12, 12, black) drawoval (148, 200, 12, 12, black) drawoval (205, 200, 12, 12, black) drawoval (262, 200, 12, 12, black) drawoval (148, 249, 12, 12, black) drawoval (205, 249, 12, 12, black) drawoval (262, 249, 12, 12, black) drawoval (316, 249, 20, 20, black) drawoval (316, 200, 13, 13, black) drawoval (316, 151, 13, 13, black) drawoval (356, 200, 13, 13, black) drawoval (396, 200, 13, 13, black) drawfillbox (285, 100, 286, 300, black) end loop |
Author: | Tony [ Wed Jan 12, 2011 6:57 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
hard to tell for sure, but I don't think you are keeping track of the state that you are in. That is, when the loop is running, how do you know if the first number has already been selected or not? |
Author: | Wajih [ Wed Jan 12, 2011 7:22 pm ] |
Post subject: | RE:Urgent Turing Calculator Help |
because it is displayed. the thing i need help is with how to make the first number(num), the symbol and the second number (num2) be seen at the same time. do i have to create a new variable? a new loop? |