IBasic Accumulator

Posted by Tara on Stack Overflow See other posts from Stack Overflow or by Tara
Published on 2009-10-20T01:08:38Z Indexed on 2010/04/09 20:33 UTC
Read the original article Hit count: 494

I am trying to do an accumulator in IBasic for a college assignment and I have the general stuff down but I cannot get it to accumulate. The code is below. My question is how do I get it to accumulate and pass to the different module.

I'm trying to calculate how many right answers the user gets. Also, i need to calculate the percentage of right answers. so if the user gets 9 out of 10 right theyed answer 90% right.

'October 15, 2009  '
'Lab 7.5 Programming Challenge 1 - Average Test Scores  '
'This is a dice game  '

declare main()  
declare inputName(name:string)  
declare getAnswer(num1:int, num2:int)  
declare getResult(num1:int, num2:int, answer:int)  
declare avgRight(getRight:int)  
declare printInfo(name:string, getRight:int, averege:float)  

openconsole  
main()  
do:until inkey$<>""  
closeconsole  
end  

sub main()  
    def name:string  
    def num1, num2, answer, total, getRight:int  
    def averege:float  
    inputName (name)  
    getRight = 0  
    For counter = 1 to 10  
        getRight = getAnswer(num1, num2)  
        getRight = getRight + 1  
    next counter  
        average = avgRight (getRight) 
    printInfo(Name, getRight, average)  
end  

sub inputName (name)  
    Input "Please enter your name: " ,name  
return  

sub getAnswer(num1, num2)  
    def answer, getRight:int    
    num1 = rnd (10) + 1  
    num2 = rnd (10) + 1  
    Print num1, "+ " ,num2  
    Input "What is the answer to the equation? " ,answer  
    getRight = getResult(num1, num2, answer)  
    return getRight

sub getResult(num1, num2, answer)   
    def getRight:int
    if answer = num1 + num2  
        getRight = 1 
    else  
        getRight = 0
    endif  
    return getRight  

sub avgRight(getRight)  
    def average:float  
    average = getRight / 10  
    return average  

sub printInfo(name, getRight, averege)  
    Print "The students name is: " ,name  
    Print "The number right is: " ,getRight   
    Print Using ("&##.#&", "The average right is " ,averege * 100, "%")  
return  

© Stack Overflow or respective owner

Related posts about programming-languages

Related posts about homework