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
Adding correct answers together to get final score
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
Easy!
For when they get one wronge:
And, for telling them which one it is:
Lets say you have 20 questions. At the beginning put:
Then, if they get it wronge:
Note that Wronge is a constant and is the equivilant to the number one. It just makes programs more readable.
For when they get one wronge:
Code: Select all
WrongeQuestions = WrongQuestions + 1
Lets say you have 20 questions. At the beginning put:
Code: Select all
DIM QuestionNumberWronge(1 TO 20)
CONST Wronge = 1
Code: Select all
WrongeQuestions = WrongQuestions + 1
QuestionNumberWronge(QuestionNumberGoesHere) = Wronge
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.
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]
So His code would look like this.
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.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.
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]
Later days,
Matthew
May those who love us love us
And those who don't
May the good Lord turn their hearts
And if he doesn't
May he turn their ankles
So we'll know them by their limping
-Irish prayer
Matthew
May those who love us love us
And those who don't
May the good Lord turn their hearts
And if he doesn't
May he turn their ankles
So we'll know them by their limping
-Irish prayer