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

Username:   Password: 
 RegisterRegister   
 buttons
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hgrad98




PostPosted: Sun Oct 27, 2013 11:23 am   Post subject: buttons

What is it you are trying to achieve?
create buttons


What is the problem you are having?
don't know how

Describe what you have tried to solve this problem
internet


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






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




PostPosted: Sun Oct 27, 2013 11:37 am   Post subject: RE:buttons

The Turing Walkthrough ( http://compsci.ca/v3/viewtopic.php?t=8808 ) is a great place to start. Especially the link to a tutorial on using the GUI module to create buttons.
hgrad98




PostPosted: Sun Oct 27, 2013 1:29 pm   Post subject: RE:buttons

nothing is working!!! omg im going insane sitting here searching the internet on how to do this!!!!! the code from the walkthrough isnt working for me!!! my code:

Turing:


%Title: Math Skills Improver/Quiz
%Created By: Hunter Grad
%Date Created: Wednesday October 23rd 2013, 12:38pm EST
%Time Of Last Edit: Wednesday October 23rd 2013, 2.27pm EST
%Course: ICS2O, Ms. Kirby
%************************************************************
%Declaring variables
var num1 : int %number 1 for computerized equation creation
var num2 : int %number 2 for computerized equation creation
var num3 : int %number 3 for computerized equation creation
var category : string %the category of math
var answer : int %user's answer input
var total : int %total number of correct answers in one game
var total2 : int %total number of correct answers in another game
var total3 : int %total number of correct answers in yet another game
var total4 : int %total number of correct answers in another different game
var total5 : int %total number of correct answers in the "all" category
total := 0 %setting the total to 0 so 1 gets added on every time the user's answer is correct
total2 := 0 %setting the total2 to 0 so 1 gets added on every time the user's answer is correct
total3 := 0 %setting the total3 to 0 so 1 gets added on every time the user's answer is correct
total4 := 0 %setting the total4 to 0 so 1 gets added on every time the user's answer is correct
total5 := 0 %setting the total5 to 0 so 1 gets added on every time the user's answer is correct
var response : string %response fom user after computer asks if they want to restart.
var hugetotal : int %The overall total at the end of the game
var randomnumber : int %a number needed to make the final calculation at the end
var randomnumber2 : int %a number needed to make the final calculation at the end
var randomnumber3 : int %a number needed to make the final calculation at the end
var randomnumber4 : int %a number needed to make the final calculation at the end
var randomnumber5 : int %a number needed to make the final calculation at the end
randomnumber := 0 %setting the 1st random number to 0
randomnumber2 := 0 %setting the 2nd random number to 0
randomnumber3 := 0 %setting the 3rd random number to 0
randomnumber4 := 0 %setting the 4th random number to 0
randomnumber5 := 0 %setting the 5th random number to 0
var score : string %used for asking the user if they want to see their total score at the end of the quiz.
var equationsign : int
%************************************************************

loop

    put "This is a math quiz that can help to improve your math skills." %telling the user what the program is
    delay (5000)
    cls %clear screen
    delay (500)
    put "There are five (5) different categories that you can take the quiz in."
    put ""
    put "Addition       Subtraction     Multiplication      Division    and    All"
    put ""
    put "Please click in the category you would like to take the quiz on." %they type in the name of the category of what they want to take the quiz on to take it
    get category
    cls
   

        color (55)
        put "You chose Addition!"
        color (black)
        for i : 1 .. 20
       
            randint (num1, 1, 30) %coming up with a random number between 1 and 30
            num1 := Rand.Int (1, 30)
            randint (num2, 1, 30) %coming up with a random number between 1 and 30
            num2 := Rand.Int (1, 30)
            put "What is ", num1, " + ", num2, "?" %asking the user a question
            put "=" ..
            get answer
            color (49) %changing the "correct" color to green
           
                if answer = num1 + num2 then
                    put "You are correct!!!"
                    put ""
                    total := total + 1
                end if
           
            color (12) %changing the "incorrect" color to red
           
                if answer > num1 + num2 then
                    put "You are incorrect!!! Answer: ", num1 + num2
                    put ""
                    total := total + 0
                end if
           
                if answer < num1 + num2 then
                    put "You are incorrect!!! Answer: ", num1 + num2
                    put ""
                    total := total + 0
                end if
            randomnumber := randomnumber + 1
            color (black)
           
        end for
        put ""
        put "Your total number of correct answers in this game is: ", total, "/20."
        put "Percentage: ", total * 5, "%" %total number of correct answers as a percentage
        put ""
        put "Do you want to take the test again? -> " ..        %does the user want to take the quiz again?
        get response
        put ""
        exit when response = "no"         %exit program if the user doesn't want to continue

   


    if category = "Subtraction" then %checking if the user chose the category "Subtraction"
       
      color (11)
     
        put "You chose Subtraction!"
        color (black)
        for i : 1 .. 20
       
            randint (num1, 15, 30) %coming up with a random number between and including 15 and 30
            num1 := Rand.Int (15, 30)                                                           %i chose to make sure that the answer will never be negative by making num1 bigger than num2 always.
            randint (num2, 1, 14) %coming up with a random number between and including 1 and 14
            num2 := Rand.Int (1, 14)
            put "What is ", num1, " - ", num2, "?" %asking the user a question
            put "=" ..
            get answer
           
            color (49) %changing the "correct" color to green
           
                if answer = num1 - num2 then
                    put "You are correct!!!"
                    put ""
                    total2 := total2 + 1
                end if
           
            color (12) %changing the "incorrect" color to red
           
                if answer > num1 - num2 then
                    put "You are incorrect!!! Answer: ", num1 - num2
                    put ""
                    total2 := total2 + 0
                end if
           
                if answer < num1 - num2 then
                    put "You are incorrect!!! Answer: ", num1 - num2
                    put ""
                    total2 := total2 + 0
                end if
           
            randomnumber2 := randomnumber2 + 1
            color (black)
           
        end for
        put ""
        put "Your total number of correct answers in this game is: ", total2, "/20."
        put "Percentage: ", total2 * 5, "%" %total number of correct answers as a percentage
        put ""
        put "Do you want to take the test again? -> " ..        %does the user want to take the quiz again?
        get response
        put ""
        exit when response = "no"         %exit program if the user doesn't want to continue
    end if

    if category = "Multiplication" then %checking if the user chose the category "Multiplication"
        color (purple)
        put "You chose Multiplication!"
        color (black)
        for i : 1 .. 20
       
            randint (num1, 1, 12) %coming up with a random number between and including 1 and 12
            num1 := Rand.Int (1, 12)
            randint (num2, 1, 12) %coming up with a random number between and including 1 and 12
            num2 := Rand.Int (1, 12)
            put "What is ", num1, " x ", num2, "?" %asking the user a question
            put "=" ..
            get answer
            color (49) %chaning the "correct" color to green
           
                if answer = num1 * num2 then
                    put "You are correct!!!"
                    put ""
                    total3 := total3 + 1
                end if
           
            color (12) %chaning the "incorrect" color to red
           
                if answer > num1 * num2 then
                    put "You are incorrect!!! Answer: ", num1 * num2
                    put ""
                    total3 := total3 + 0
                end if
           
                if answer < num1 * num2 then
                    put "You are incorrect!!! Answer: ", num1 * num2
                    put ""
                    total3 := total3 + 0
                end if
           
            randomnumber3 := randomnumber3 + 1
            color (black)
           
        end for
        put ""
        put "your total number of correct answers in this game is: ", total3, "/20."
        put "Percentage: ", total3 * 5, "%" %number of correct answers as a percentage
        put ""
        put "Do you want to take the test again? -> " ..        %does the user want to take the quiz again?
        get response
        put ""
        exit when response = "no" %exit program if the user doesn't want to continue
       
    end if

    if category = "Division" then
        color (35)
        put "You chose Division!"
        color (black)
        for i : 1 .. 20
       
            randint (num1, 1, 12)
            num1 := Rand.Int (1, 12)
            randint (num2, 1, 12)
            num2 := Rand.Int (1, 12)
            num3 := num1 * num2
            put "What is ", num3, " ? ", num2, "?"
            put "=" ..
            get answer
           
            color (49) %changing the "correct" color to green
           
                if answer = num3 / num2 then
                    put "You are correct!!!"
                    put ""
                    total4 := total4 + 1
                end if
           
            color (12) %changing the "incorrect" color to red
           
                if answer > num3 / num2 then
                    put "You are incorrect!!! Answer: ", num3 / num2
                    put ""
                    total4 := total4 + 0
                end if
           
                if answer < num3 / num2 then
                    put "You are incorrect!!!"
                    put ""
                    total4 := total4 + 0
                end if
           
            randomnumber4 := randomnumber4 + 1
            color (black)
           
        end for
        put ""
        put "Your total number of correct answers in this game is: ", total4, "/20."
        put "Percentage: ", total4 * 5, "%"
        put ""
        put "Do you want to take the quiz again? -> " ..
        get response
        put ""
        exit when response = "no"
       
    end if
   
    if category = "All" then
        color (112)
        put "You chose all categories!"
        color (black)
        for i : 1 .. 20
           
            randint (equationsign, 1, 4)
            equationsign := Rand.Int (1, 4)
           
                color (black)
           
                if equationsign = 1 then
                   
                    randint (num1, 1, 30)
                    num1 := Rand.Int (1, 30)
                   
                    randint (num2, 1, 30)
                    num2 := Rand.Int (1, 30)
                   
                    put "What is ", num1, " + ", num2, "?"
               
                get answer
               
                    color (49)
                   
                    if answer = num1 + num2 then
                        put "You are correct!!!"
                        put ""
                        total5 := total5 + 1
                    end if
                   
                    color (12)
                   
                    if answer > num1 + num2 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if
                   
                    if answer < num1 + num2 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if
                   
                end if
               
                color (black)
               
                if equationsign = 2 then
               
                randint (num1, 1, 14)
                num1 := Rand.Int (1, 14)
               
                randint (num2, 15, 30)
                num2 := Rand.Int (15, 30)
               
                    put "What is ", num2, " - ", num1
                   
                get answer
               
                    color (49)
                   
                    if answer = num2 - num1 then
                        put "You are correct!!!"
                        put ""
                        total5 := total5 + 1
                    end if
                   
                    color (12)
                   
                    if answer > num2 - num1 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if
                   
                    if answer < num2 - num1 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if

                   
                end if
               
                color (black)
               
                if equationsign = 3 then
                   
                    randint (num1, 1, 12)
                    num1 := Rand.Int (1, 12)
                   
                    randint (num2, 1, 12)
                    num2 := Rand.Int (1, 12)
                   
                    put "What is ", num1, " x ", num2
                   
                get answer
               
                    color (49)
                   
                    if answer = num1 * num2 then
                        put "You are correct!!!"
                        put ""
                        total5 := total5 + 1
                    end if
                   
                    color (12)
                   
                    if answer > num1 * num2 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if
                   
                    if answer < num1 * num2 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if
                   
                end if
               
                color (black)
               
                if equationsign = 4 then
                   
                    randint (num1, 1, 12)
                    num1 := Rand.Int (1, 12)
                   
                    randint (num2, 1, 12)
                    num2 := Rand.Int (1, 12)
                   
                    num3 := num1 * num2
                   
                    put "What is ", num3, " ? ", num1
                   
                get answer
               
                    color (49)
                   
                    if answer = num3 / num1 then
                        put "You are correct!!!"
                        put ""
                        total5 := total5 + 1
                    end if
                   
                    color (12)
                   
                    if answer > num3 / num1 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if
                   
                    if answer < num3 / num1 then
                        put "You are incorrect!!!"
                        put ""
                        total5 := total5 + 0
                    end if
               
                end if
                color (black)
            randomnumber5 := randomnumber5 + 1
        end for
        put ""
        put "Your total number of correct answers in this game is: ", total5, "/20."
        put "Percentage: ", total5 * 5, "%" %total number of correct answers as a percentage
        put ""
        put "Do you want to take the test again? -> " ..        %does the user want to take the quiz again?
        get response
        put ""
        exit when response = "no"         %exit program if the user doesn't want to continue
   
    end if
   
end loop


put "Would you like to know your score? (yes/no) " ..
get score
put ""
            if score = "yes" then
                put "Your overall total for every game you played together is: ", total + total2 + total3 + total4 + total5, "/", (randomnumber + randomnumber2 + randomnumber3 + randomnumber4 + randomnumber5)
                put "Overall percentage: ", ((total + total2 + total3 + total4 + total5) / (randomnumber + randomnumber2 + randomnumber3 + randomnumber4 + randomnumber5)) * 100, "%"
            end if
           
            if score = "no" then
                put "Ok. Hope you try again some time soon! Bye!"
            end if


i need to have it so that there are buttons that you click to choose the category instead of typing! someone please just show me what to do instead of saying look at this website! "no offense demonwasp but everybody just says look at this website, or this one!!! someone just show me please with code!! thanks
DemonWasp




PostPosted: Sun Oct 27, 2013 1:36 pm   Post subject: RE:buttons

Members of compsci.ca will not do homework for you.

I noticed that your code never calls GUI.CreateButton ... or anything else from the GUI module. How were you hoping that it would work without even trying anything?

Try creating a separate "example" program that has two buttons. If you press the first button, it prints "A", and if you press the second button, it prints "B". Use the "GUI" examples in the Turing Walkthrough. Once you've got that working, you should be able to modify your main program to use what you learned from your example.

By the way, half of being a software developer is knowing how to find the right resource (website, book, manual, API documentation, ...) to read and reading that. Very little time is actually spent writing code.
hgrad98




PostPosted: Sun Oct 27, 2013 1:42 pm   Post subject: RE:buttons

all of the homework is done. that whole code was my project. my teacher said if you want a level 3 then you just do multiplication, addition and subtraction. if you want a level 4, then you have to also do division and all four categories together. also showing their score after each game, making it possible to take the test again and again, then showing their total score. AND adding something we DIDN'T learn in class. that's why im asking. because i don't know it. i wasn't taught it. but i have everything done for the level 4 except for something i wasn't taught. so i was just asking for a little bit of help to guide me in the right direction. not a site. thanks. and i looked at the Turing Walkthrough for a while. several times
hgrad98




PostPosted: Sun Oct 27, 2013 1:44 pm   Post subject: RE:buttons

i also know where to look for the help. i have searched all over the place online, and on the turing "reference" part that is part of turing. all of there examples work but when i try to put it into my code, it doesnt work.
Insectoid




PostPosted: Sun Oct 27, 2013 1:48 pm   Post subject: RE:buttons

Do you know why or how it works? You can't just copy & paste preexisting code into your projects and expect it to work. You need to how and why it works in order to adapt it to your own code. Did you actually read the article in the Turing Walkthrough or just look at the code? Did you read the reference?
hgrad98




PostPosted: Sun Oct 27, 2013 1:54 pm   Post subject: RE:buttons

i read them about twice each. tried it on my own. with my code: didn't work. then i tried copying it. didnt work either
Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Sun Oct 27, 2013 3:58 pm   Post subject: RE:buttons

Post the code you've tried, and we'll try to help you out.
hgrad98




PostPosted: Sun Oct 27, 2013 6:21 pm   Post subject: RE:buttons

Turing:


import GUI


 put "There are five (5) different categories that you can take the quiz in."
    put ""
    var Addition : int := GUI.CreateButton (50, 10, 0, "Addition",
    var Subtraction : int := GUI.CreateButton (150, 10, 0, "Subtraction",
    var Multiplication : int := GUI.CreateButton (250, 10, 0, "Multiplication",
    var Division : int := GUI.CreateButton (350, 10, 0, "Division",
    var All : int := GUI.CreateButton (450, 10, 0, "All",
    put ""
    put "Please click in the category you would like to take the quiz on."


and it doesnt work. i wasn't taught it in class, so it isn't homework. it is adding to my "finished" assignment to get better marks. i want to make a button for each category: Addition, Subtraction, Multiplication, Division, and All (all 4 together)
thanks
Insectoid




PostPosted: Sun Oct 27, 2013 6:33 pm   Post subject: RE:buttons

Well, for one thing you're missing your associated procedures and closing brackets. Read your error codes. They usually tell you what's wrong.
DemonWasp




PostPosted: Sun Oct 27, 2013 6:40 pm   Post subject: RE:buttons

Since it's for marks in school, it's still in the "we can help, but won't write code for you" category.

It looks like you've forgotten to specify a "callback" method for your buttons, and you've forgotten to close the open-brackets. You also forgot the "event processing loop".

Here's a minimal example for how to draw two buttons. One puts "Hello world" in the top left, while the other clears the topmost line. Note that you have to specify the procedure to call when the button is clicked when you create the button.

Turing:

import GUI

procedure say_hello ()
    Text.Locate ( 1, 1 )
    put "Hello world"
end say_hello

procedure clear ()
    Text.Locate ( 1, 1 )
    put ""
end clear

var hello_button : int := GUI.CreateButton ( 50, 50, 0, "Hello", say_hello )
var clear_button : int := GUI.CreateButton ( 50, 150, 0, "Clear", clear )


loop
    exit when GUI.ProcessEvent()
end loop

hgrad98




PostPosted: Sun Oct 27, 2013 7:05 pm   Post subject: RE:buttons

ok i figured out what does what in your code. understand it, opened a new turing. copied pasted. i ran it, it worked. i closed that turing. now i fixed the issues with my code but it still doesnt work. it says that some of my variables aren't imported
hgrad98




PostPosted: Sun Oct 27, 2013 7:07 pm   Post subject: RE:buttons

and that the GUI wasnt imported. even though at the top of my program, i typed
import GUI.
hgrad98




PostPosted: Sun Oct 27, 2013 7:19 pm   Post subject: RE:buttons

an error code at procedure Addition says: 'procedure' may only be declared at the program, module, or monitor level. what does that mean?
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 2  [ 26 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: