Page 1 of 1

Adding correct answers together to get final score

Posted: Mon May 30, 2005 1:07 am
by dave_
I need desperate help with a project i am undertaking. It is in the form of a quiz and uses structed programming ie SUBs and CASEs instead of IFs.
The problem i am having is i cant figure out how to get a score happening.
the program is simple and text with the slighest of formatting only. Every time an answer is correct i need to be able to take it and store it for a few minutes then retreive it when the quiz is over to tell the user how many questions they answered correctly. Any help would be great

Posted: Mon May 30, 2005 2:34 am
by Nodtveidt
One word: variables. :D

Posted: Mon May 30, 2005 9:05 am
by {Nathan}
Easy!

For when they get one wronge:

Code: Select all

WrongeQuestions = WrongQuestions + 1
And, for telling them which one it is:

Lets say you have 20 questions. At the beginning put:

Code: Select all

DIM QuestionNumberWronge(1 TO 20)
CONST Wronge = 1
Then, if they get it wronge:

Code: Select all

WrongeQuestions = WrongQuestions + 1
QuestionNumberWronge(QuestionNumberGoesHere) = Wronge
Note that Wronge is a constant and is the equivilant to the number one. It just makes programs more readable.

Posted: Tue May 31, 2005 2:39 am
by dave_ forgot to login
thanks for the help but i still cannot get it to work. its tells me i have a "duplicate definition". is this becasue im using SUBs?? any way if u could work it out and give me an example of how to give the total CORRECT answers at the end of my 22 questions it would be sweet. Cheers

Posted: Wed Jun 01, 2005 12:13 am
by Levi
Well Total correct answers is not different than total wrong answers. Simply Change the word wrong in his examples to correct and increase teh number of correct answers and set the array to 1 when correct.

So His code would look like this.
Easy!

For when they get one Right:

Code: Select all

QuestionsCorrect = QuestionsCorrect + 1 

And, for telling them which one it is:

Lets say you have 20 questions. At the beginning put:

Code: Select all

 
DIM QuestionNumberCorrect(1 TO 20) 
CONST Correcty = 1 

Then, if they get it right:

Code: Select all

QuestionsCorrect = QuestionsCorrect + 1 
QuestionNumberCorrect(QuestionNumberGoesHere) = Correcty 

Note that "Correcty" is a constant and is the equivilant to the number one. It just makes programs more readable.
Very simple. Now I don't claim to be an expert here as I try to avoid learning about local and global variables ( I do this by not programming often) but a duplicate definition usually means you've used two variables with the same name somewhere, two subs, to line positions like using 10 twice or Thisisaline: for using Goto's.

Ummm...I think that when variables are placed into subs they are local to that sub. And so reusing the names shouldn't be a problem. Unless that isn't the case in QB. In which case make sure all of your variables are different. But there shouldn't be a problem there.

If you use a DIM SHARED command with your variables then they become global and you have to make sure no variable has the same name.

Anyone please correct me if I'm wrong.[/code]