Re: How do I get this program to ask more than one question?

new topic     » goto parent     » topic index » view thread      » older message » newer message
bubba said...

<snip>

Use "Quoted Reply" and:

<eucode> 
-- eucode 
</eucode> 

Without the {} curly brackets.

Also Use "Preview" before you post a message so that you can edit your formatting mistakes.

bubba said...

I am trying to write a quiz program that will ask 10 or 20 random questions and then grade it. I got it working great for the first question, but can't figure out how to ask another question.

I am obviously missing something very big in my Euphoria knowledge.

This is a stripped down version for your perusal.

 
 
--handler.exw - written by Ron Austin 386-688-4057 
without warning 
with trace 
 
include win32lib.ew -- win32 library 
include datetime.e 
include gstring.e -- George Walters string functions 
 
atom correct 
object Win,Win1,Win2,Win3,record,Win4,ans1,ans2,ans3,ans4 
sequence Data,text,key,test,keyindex,right,wrong,question,answer1,answer2,answer3,answer4,rightans 
integer ct,recs,line,Okay,ans,	qcount,fields,RecNum 
 
question=repeat(0,5) 
answer1=repeat(0,5) 
answer2=repeat(0,5) 
answer3=repeat(0,5) 
answer4=repeat(0,5) 
right=repeat(0,5) 
qcount=5 
fields = 9 
Okay=0 
Data = repeat(0,fields) 
 
constant 
Ver = "Version 1.0", 
App = "Handler Demo" 
----------------------------------------------------------------------------- 
-- @ MAIN CONTROLS 
----------------------------------------------------------------------------- 
    Win  =  createEx( Window,"Handler Test", 0, Center,Center,800,500,0,0) 
    Win1 =  create( Window, "Window one", Win, 5,  10, 770, 40, {WS_CHILD,WS_BORDER} ) 
    Win2 =  create( Window, "Window two",  Win, 5,  60, 770, 250, {WS_CHILD,WS_BORDER} ) 
    Win3 =  create( Window, "Selection",Win, 5, 320, 770, 100, {WS_CHILD,WS_BORDER} )  
     
    ans1 = create(Radio,"",Win2,5,22,12, 12,0)   
    ans2 = create(Radio,"",Win2,5,62,12, 12,0)   
    ans3 = create(Radio,"",Win2,5,102,12, 12,0)   
    ans4 = create(Radio,"",Win2,5,142,12, 12,0)   
   
     
                                                
    setFont( Win1, "Arial", 12, Bold ) 
    setFont( Win2, "Arial", 16, Bold+Italic ) 
    setFont( Win3, "Arial", 12, Bold ) 
-----------------------------------------------------------------------------                           
-- @ LOAD QUESTIONS  --  Final program will load questions and answers from disk file 
-----------------------------------------------------------------------------    
procedure LoadQuestions() 
question[1]="WHO IS BURIED IN GRANT'S TOMB?" 
question[2]="5 + 5 = ?" 
question[3]="HOW MANY TEETH DOES AN ADULT HUMAN HAVE?" 
question[4]="WHAT IS THE CAPITAL OF THE STATE OF FLORIDA?" 
question[5]="APPROXAMENTALY HOW MILES IS IT TO THE SUN?" 
 
answer1[1]="GRANT" 
answer2[1]="LINCON" 
answer3[1]="NOBODY" 
answer4[1]="WASHINGTON" 
 
answer1[2]="5" 
answer2[2]="10" 
answer3[2]="25" 
answer4[2]="50" 
 
answer1[3]="36" 
answer2[3]="35" 
answer3[3]="32" 
answer4[3]="40" 
 
answer1[4]="MIAMI" 
answer2[4]="ORLANDO" 
answer3[4]="JACKSONVILLE" 
answer4[4]="TALLAHASSEE" 
 
answer1[5]="90,000,000" 
answer2[5]="89,000,000" 
answer3[5]="93,000,000" 
answer4[5]="91,000,000" 
 
right[1]="A" 
right[2]="B" 
right[3]="C" 
right[4]="D" 
right[5]="C" 
end procedure 
------------------------------------------------------------------------------- 
------------------------------------------------------------------------------- 
-- @ INITIALIZE PROGRAM 
------------------------------------------------------------------------------- 
------------------------------------------------------------------------------- 
LoadQuestions()  
 
procedure DisplayQuestion () 
    line=15 
    setPenPosition(Win1,5,line) 
    wPuts( Win1,question[RecNum]) 
     
    setPenPosition(Win2,30,line) 
    wPuts(Win2,answer1[RecNum]) 
    line=line+40 
    
    setPenPosition(Win2,30,line) 
    wPuts(Win2,answer2[RecNum]) 
    line=line+40 
     
    setPenPosition(Win2,30,line) 
    wPuts(Win2,answer3[RecNum]) 
    line=line+40   
     
    setPenPosition(Win2,25,line) 
    wPuts(Win2,answer4[RecNum])  
end procedure 
 
------------------------------------------------------------------------------- 
-- @ ACTIVATE PROGRAM 
-------------------------------------------------------------------------------- 
    procedure Activate_MainWin(integer self, integer event, sequence parms)    
    openWindow(Win1,Normal) 
    openWindow(Win2,Normal) 
    openWindow(Win3,Normal) 
    RecNum = rand(qcount) 
    DisplayQuestion() 
end procedure 
 
 
----------------------------------------------------------------------- 
-- Accept Answer 
----------------------------------------------------------------------- 
procedure Next_Question(integer self, integer event, sequence parms)  
 
 for i= 1 to 3 do 
    repaintWindow(Win1) 
    repaintWindow(Win2) 
    repaintWindow(Win3) 
    RecNum = rand(qcount) 
    key=keyindex[RecNum] 
    DisplayQuestion() 
    end for   
 end procedure 
  
procedure Accept(integer self, integer event, sequence parms) 
 
-- find out which radio button was picked 
    ans=0 
         if isChecked(ans1) then ans=2 
         end if 
         if isChecked(ans2) then ans=3 
         end if       
         if isChecked(ans3) then ans=4 
         end if        
         if isChecked(ans4) then ans=5 
         end if  
          
-- convert letter of right answer to a number                
         correct=0 
         if equal (right[RecNum],"A") then  
                   correct=2  
                   rightans=answer1[RecNum] 
            end if            
         if equal (right[RecNum],"B") then  
                   correct=3 
                   rightans=answer2[RecNum] 
            end if         
        if equal (right[RecNum],"C") then  
                  correct=4  
                  rightans=answer3[RecNum] 
            end if    
        if equal (right[RecNum],"D") then  
                  correct=5 
                  rightans=answer4[RecNum]  
            end if 
             
        setPenPosition(Win3,10,10) 
        wPuts(Win3,"The correct answer is") 
        setPenPosition(Win3,10,40) 
 --       wPuts(Win3,Data[correct])      
 wPuts(Win3,rightans)  
 
-- create pushbutton         
         Okay   =     create( PushButton, " Next Question", Win3, 500, 20, 100, 40, 0 )   
         end procedure 
          
------------------------------------------------------------------------------- 
-- @ SETUP HANDLERS 
--------------------------------------------------------------------------------          
          
 setHandler(Win, w32HActivate, routine_id("Activate_MainWin"))           
          
 setHandler({ans1,ans2,ans3,ans4}, w32HClick, routine_id( "Accept" )) 
  
 setHandler(Okay,w32HClick, routine_id( "Next_Question" ))   
------------------------------------------------------------------------------- 
-- @ MAIN PROGRAM 
------------------------------------------------------------------------------- 
    WinMain( Win, Normal 

Peace jcmarsh

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu