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