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

Username:   Password: 
 RegisterRegister   
 Radio Button Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rumman




PostPosted: Mon Dec 26, 2005 6:41 pm   Post subject: Radio Button Help

I am a new programmer, and I am learning a bit about Turing in school. I have this cumulative activity to do, and I cannot get this program to display "Correct Answer" when the user submits the correct answer. Also, when the user has completed the first question, they are not able to view the second question. Can anyone please help, and suggest if I may be able to minimize the code length?

code:

import GUI
View.Set ("graphics")

%%%%%%%%%%%%%%%%%%
%                                                %
%                   QUESTION 1           %
%                                                %
%%%%%%%%%%%%%%%%%%

% Declare the variable(s) for each radio button to be used.
var ans1: int
var ans2: int
var ans3: int
var ans4: int

% Declare the procedure(s) to be used with the radio buttons. I customized my
% radio buttons so that when one of them is selected, all the other radio
% buttons are disable. This ensures the user only chooses one (1) answer.
procedure status1 (filled : boolean)
    if filled then
    GUI.Disable (ans2)
    GUI.Disable (ans3)
    GUI.Disable (ans4)
    else
    GUI.Enable (ans2)
    GUI.Enable (ans3)
    GUI.Enable (ans4)
    end if
end status1

procedure status2 (filled : boolean)
    if filled then
    GUI.Disable (ans1)
    GUI.Disable (ans3)
    GUI.Disable (ans4)
    else
    GUI.Enable (ans1)
    GUI.Enable (ans3)
    GUI.Enable (ans4)
    end if
end status2

procedure status3 (filled : boolean)
    if filled then
    GUI.Disable (ans1)
    GUI.Disable (ans2)
    GUI.Disable (ans4)
    else
    GUI.Enable (ans1)
    GUI.Enable (ans2)
    GUI.Enable (ans4)
    end if
end status3

procedure status4 (filled : boolean)
    if filled then
    GUI.Disable (ans1)
    GUI.Disable (ans2)
    GUI.Disable (ans3)
    else
    GUI.Enable (ans1)
    GUI.Enable (ans2)
    GUI.Enable (ans3)
    end if
end status4

% Finally, create the check boxes that will be used to select the answer.
ans1 := GUI.CreateCheckBox (10, 10, "Check Box 1",
    status1)
ans2 := GUI.CreateCheckBoxFull (200, 10, "Check Box 2",
    status2, GUI.RIGHT, '2')
ans3 := GUI.CreateCheckBoxFull (200, 50, "Check Box 3",
    status3, GUI.RIGHT, '2')
ans4 := GUI.CreateCheckBoxFull (200, maxy - 20, "Check Box 4",
    status4, GUI.RIGHT, '2')   

% Make a submit button to clear the screen and introduce the next question.
var quitBtn : int := GUI.CreateButton (230, 10, 0, "Next Question", GUI.Quit)

% These statements will allow us to properly use the submit button.
loop
    exit when GUI.ProcessEvent
end loop

% Now, we have to know the status of the checkboxex to know whether the answer
% is correct or not.
var ans1status : boolean := GUI.GetCheckBox (ans1)
var ans2status : boolean := GUI.GetCheckBox (ans2)
var ans3status : boolean := GUI.GetCheckBox (ans3)
var ans4status : boolean := GUI.GetCheckBox (ans4)

% We are now making sure that the correct answer is chosen.
if ans3status= true then
    put "Congratulations. You are correct."
else
    cls
    delay (100)
    put "Wrong answer"
end if


%%%%%%%%%%%%%%%%%%
%                                                %
%                   QUESTION 2           %
%                                                %
%%%%%%%%%%%%%%%%%%

% Declare the variable(s) for each radio button to be used.
var ans11: int
var ans12: int
var ans13: int
var ans14: int

% Declare the procedure(s) to be used with the radio buttons. I customized my
% radio buttons so that when one of them is selected, all the other radio
% buttons are disable. This ensures the user only chooses one (1) answer.
procedure status11 (filled : boolean)
    if filled then
    GUI.Disable (ans12)
    GUI.Disable (ans13)
    GUI.Disable (ans14)
    else
    GUI.Enable (ans12)
    GUI.Enable (ans13)
    GUI.Enable (ans14)
    end if
end status11

procedure status12 (filled : boolean)
    if filled then
    GUI.Disable (ans11)
    GUI.Disable (ans13)
    GUI.Disable (ans14)
    else
    GUI.Enable (ans11)
    GUI.Enable (ans13)
    GUI.Enable (ans14)
    end if
end status12

procedure status13 (filled : boolean)
    if filled then
    GUI.Disable (ans11)
    GUI.Disable (ans12)
    GUI.Disable (ans14)
    else
    GUI.Enable (ans11)
    GUI.Enable (ans12)
    GUI.Enable (ans14)
    end if
end status13

procedure status14 (filled : boolean)
    if filled then
    GUI.Disable (ans11)
    GUI.Disable (ans12)
    GUI.Disable (ans13)
    else
    GUI.Enable (ans11)
    GUI.Enable (ans12)
    GUI.Enable (ans13)
    end if
end status14

% Finally, create the check boxes that will be used to select the answer.
ans11 := GUI.CreateCheckBox (10, 10, "Check Box 1",
    status11)
ans12 := GUI.CreateCheckBoxFull (200, 10, "Check Box 2",
    status12, GUI.RIGHT, '2')
ans13 := GUI.CreateCheckBoxFull (200, 50, "Check Box 3",
    status13, GUI.RIGHT, '2')
ans14 := GUI.CreateCheckBoxFull (200, maxy - 20, "Check Box 4",
    status14, GUI.RIGHT, '2')   

% Make a submit button to clear the screen and introduce the next question.
var quitBtn2 : int := GUI.CreateButton (230, 10, 0, "Next Question", GUI.Quit)

% These statements will allow us to properly use the submit button.
loop
    exit when GUI.ProcessEvent
end loop

% Now, we have to know the status of the checkboxex to know whether the answer
% is correct or not.
var ans11status : boolean := GUI.GetCheckBox (ans11)
var ans12status : boolean := GUI.GetCheckBox (ans12)
var ans13status : boolean := GUI.GetCheckBox (ans13)
var ans14status : boolean := GUI.GetCheckBox (ans14)

% We are now making sure that the correct answer is chosen.
if ans13status= true then
    put "Congratulations. You are correct."
else
    cls
    delay (100)
    put "Wrong answer"
end if


(Please forgive me for putting too many comments)[/code]
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Dec 26, 2005 8:28 pm   Post subject: Re: Radio Button Help

rumman wrote:
suggest if I may be able to minimize the code length?

Well your question two part is identical to question 1, other than the different question being asked. Otherwise all the setup, variables, procedures... all the same. It's redundant.

Reuse the code you already have. This way you have to get it working right just once.. for that very first question, and every next one will work identically well.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
rumman




PostPosted: Mon Dec 26, 2005 10:28 pm   Post subject: (No subject)

I understand that the coding is redundant for the second question. However, I cannot figure out a way to load the next question and make the new checkboxes available for use. If you try my code in Turing, you can see that after you click the "Next Question" button, the new checkboxes are not selectable. Is there any way I can fix that?
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  [ 3 Posts ]
Jump to:   


Style:  
Search: