Adding correct answers together to get final score

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
dave_
Newbie
Posts: 1
Joined: Mon May 30, 2005 1:01 am

Adding correct answers together to get final score

Post by dave_ » Mon May 30, 2005 1:07 am

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

User avatar
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt » Mon May 30, 2005 2:34 am

One word: variables. :D

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Mon May 30, 2005 9:05 am

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.
Image

dave_ forgot to login

Post by dave_ forgot to login » Tue May 31, 2005 2:39 am

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

User avatar
Levi
Veteran
Posts: 79
Joined: Tue Jul 27, 2004 11:44 pm
Location: Alone and forgotten
Contact:

Post by Levi » Wed Jun 01, 2005 12:13 am

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]
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

Post Reply