Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to Pascal, some help would be greatly appreciated!

Status
Not open for further replies.

chrisgarvey

Technical User
Mar 27, 2003
64
GB
Hello,

I am trying to create my first Pascal Program.

The program is suposed to read in the contence of 2 arrays;
- 1 has the student anwsers to a multi choice exam paper
- other has a specimin anwser.

I am trying to create a program that marks the papers, (there is only 1 correct anwser) and returns the anwser as both:
- a figure out of 10
- a percentage

Below is my code, I would be extremly greatful is someone could look over it for me.

{Program to mark a 10 question multi choice paper}

USES CRT;

{array of anwsers 1 to 10}
Anwser [1] = A
Anwser [2] = B
Anwser [3] = B
Anwser [4] = E
Anwser [5] = A
Anwser [6] = C
Anwser [7] = B
Anwser [8] = A
Anwser [9] = D
Anwser [10] = E

{Array of student anwser 1 to 10}
StudentAnwser [1] = B
StudentAnwser [1] = B
StudentAnwser [1] = B
StudentAnwser [1] = B
StudentAnwser [1] = B
StudentAnwser [1] = E
StudentAnwser [1] = E
StudentAnwser [1] = E
StudentAnwser [1] = D
StudentAnwser [1] = C


{Declaring Variables}

Counter = 0
Score = 0

{Begin Program}
BEGIN
CLRSCR;

Counter = Counter+1;

If Counter > 10 then;
WRITELN('Your Score is'(counter));
WRITELN('Your Percentage Score is'(Counter/10*100)'%');
else;
If StudentAnwser[Counter] = Anwser[Counter];
{correct anwser so add 1 to score}
THEN Score = Score+1;
else;
{incorrect anwser so do nothing}
endif;
endif;
END.

 
.. you've got the bones of it, but it needs some fleshing out as you will have found if you tried running it.
If you break the problem down into smaller bits you'll notice that you have to do a simple task ten times. You have to check the answer, and you have to keep doing it.
So you need to look at some sort of loop that will run ten times (or, for flexibility, until there are no more answers to look at.
Once you've got your loop, think about what it needs to do. It doesn't need to report the answer, just look at whether the answer is right or not. Therefore you don't really need to have that if count > 10... Just put your output code after the loop. But remember that even if the student got the answer wrong, you still need to move on to the next answer and not examine the first one ten times!
Do have a look at your setting-up code; I'm not sure you're setting the student's answers usefully...
Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top