My quiz program : help need
Author |
Message |
NegativeAzn
![](http://compsci.ca/v3/uploads/user_avatars/11448788884935e9eda986e.jpg)
|
Posted: Thu Oct 25, 2007 4:15 pm Post subject: My quiz program : help need |
|
|
Hi, im pretty new to this "Turing program" i was wondering if you guys can sorta help thanks, well im trying to create a program with 10 questions with 4 choices ( multiple choice). Thing required in this program is using this thing called loop, exit when "variable word" = "word designated", and is to show how many answers they ahve gotten correct out of 10 in to a percent ex. 5/10 = 50%.
where i need Help part:
* i tried searching but i failed to find, yes i stink at searching for this help ):
1 )i still havent perfect how to loop with the exit when = word thing, not sure how to work it properly
2 ) how to display how many answers the tester/quizzer got out of 10.
3 ) how to end if , when i enter at the bottom of all code, syntax error says need end if when i have it.
4 ) when this is looped, the score has to be resets
well heres a rough copy of my code, still needs ALot of editing and help please help if you can .
i sorta didnt event test this out yet cause i can run it cause of the end if part ):
Turing: |
%QUIZ PROGRAM ): WHERE I STINK
var answer1 : int := 0
var answer2 : int := 0
var answer3 : int := 0
var answer4 : int := 0
var answer5 : int := 0
var answer6 : int := 0
var answer7 : int := 0
var answer8 : int := 0
var answer9 : int := 0
var answer10 : int := 0
var word : string := ""
var conversion : real := 0.0
var correctanswers : real := 0.0
put" --------------------------------------------------"
put"| 10 Pratcice Driving Questions Quiz :By NegativeAzn: |"
put" --------------------------------------------------"
put"Please answer these questions using 1, 2, 3 or 4 Thank You"
put"Question 1. If you are going into a curve too quickly, you should: "
put"1. Slam on your brakes."
put"2. Pump the brakes, gradually slowing down until you can stop"
put"3. Pull the emergency brake and steer into the curve."
put"4. Ease off the accelerator, then speed up slightly as you regain more control."
get answer1
if answer1 = 4 then
put "You are correct"
else
put "Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 2. When approaching a railway crossing you should :"
put"1. Watch for warning lights that indicate an approaching train."
put"2. Watch for motorcycle riders and cyclists who may slip on the wet tracks."
put"3. Realize that trains always have the right of way."
put"4. All of the above."
get answer2
if answer2 = 4 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 3. When should you use your car's signals? "
put"1. When changing lanes."
put"2. When turning a corner."
put"3. When pulling out from a line of parked vehicles."
put"4. All of the above."
get answer3
if answer3 = 4 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 4. When pulling away from the curb, you should: "
put"1. Shoulder check, then pull out when safe."
put"2. Check your rear-view mirror, then pull out when safe."
put"3. Signal, shoulder check, then pull out when safe."
put"4. Signal, check your rear-view mirror, then pull out when safe."
get answer4
if answer4 = 3 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 5. As you are driving, you should: "
put"1. Keep to the right-hand side of the lane."
put"2. Keep to the left-hand side of the lane."
put"3. Keep to the center of the lane"
put"4. It depends on which lane you are in and the hazards that are around you"
get answer5
if answer5 = 4 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 6. When approaching a stop sign where there is no stop line, sidewalk or crosswalk you should: "
put"1. Stop 3 metres back from the intersection and inch up slowly."
put"2. Slow down and proceed with caution."
put"3. Stop just before you enter the intersection."
put"4. Stop only if pedestrians are waiting to cross."
get answer6
if answer6 = 3 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 7. A sign showing a green circle with a straight arrow pointing upwards inside it means: "
put"1. Straight road ahead."
put"2. One lane ahead."
put"3. No turns, drive through only."
put"4. A. and C. are correct."
get answer7
if answer7 = 3 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 8. At uncontrolled intersections you should always: "
put"1. Come to a complete stop, make sure it is safe and proceed with caution."
put"2. Slow down, make sure it is safe and proceed with caution."
put"3. Stop well before the intersection and inch out slowly; only proceed when no cars are approaching."
put"4. Speed right on through."
get answer8
if answer8 = 2 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 9. When can you make a right turn at a red light? "
put"1. After slowing down to check for oncoming traffic."
put"2. After coming to a complete stop and yielding to both traffic and pedestrians."
put"3. Anytime there are no signs prohibiting a right turn on a red light."
put"4. B. and C. are correct."
get answer9
if answer9 = 4 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Question 10. If someone is tailgating you, you should: "
put"1. Slow down slightly to increase the space in front of your car, allowing you extra space to stop more gradually if you need to"
put"2. Move into another lane."
put"3. Pull over to let the tailgater pass"
put"4. All of the above.."
get answer10
if answer10 = 4 then
put "You are correct"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Thank you, you have finished your driving practice test."
conversion := correctanswers*10
put "In this test you got ", correctanswers ,"Which is ", conversion, "percent"
end if
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Euphoracle
![](http://compsci.ca/v3/uploads/user_avatars/11170373664bf5f25f636f1.png)
|
Posted: Thu Oct 25, 2007 4:32 pm Post subject: RE:My quiz program : help need |
|
|
A prime example of a program that needs arrays, loops, and structure
@ Schools
ALSO, you are missing "end if" after EVERY selection except the last one. You aren't using elsif, so you need to end them. Add it in. (It'd be easier if you used a loop & arrays because you could make 1 edit rather than editing many things in a copypaste job) |
|
|
|
|
![](images/spacer.gif) |
NegativeAzn
![](http://compsci.ca/v3/uploads/user_avatars/11448788884935e9eda986e.jpg)
|
Posted: Thu Oct 25, 2007 5:00 pm Post subject: RE:My quiz program : help need |
|
|
yes i do, if you made that siggie you seem very good at photoshop, ok now to be on topic, you just went total balistic pro on me about loop and arrays i got tottaly lost, i got the part where i have to add end if aftter every else but everything else i was like O_O |
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Thu Oct 25, 2007 5:03 pm Post subject: RE:My quiz program : help need |
|
|
The Turing Walkthrough is your best friend in situations like these. Check out specifically the section on arrays and loops |
|
|
|
|
![](images/spacer.gif) |
NegativeAzn
![](http://compsci.ca/v3/uploads/user_avatars/11448788884935e9eda986e.jpg)
|
Posted: Thu Oct 25, 2007 5:11 pm Post subject: RE:My quiz program : help need |
|
|
BIG EDIT!!!
i fixed much things, here. but for some reason wen my correct answers count is always 10, can someone explain why?
Turing: |
%QUIZ PROGRAM ): WHERE I STINK
var answer1 : int := 0
var answer2 : int := 0
var answer3 : int := 0
var answer4 : int := 0
var answer5 : int := 0
var answer6 : int := 0
var answer7 : int := 0
var answer8 : int := 0
var answer9 : int := 0
var answer10 : int := 0
var number : string := ""
var conversion : real := 0.0
var correctanswers : real := 0.0
loop
put" --------------------------------------------------"
put"| 10 Pratcice Driving Questions Quiz :By NegativeAzn: |"
put" --------------------------------------------------"
put"Please answer these questions using 1, 2, 3 or 4 Thank You"
put"Question 1. If you are going into a curve too quickly, you should: "
put"1. Slam on your brakes."
put"2. Pump the brakes, gradually slowing down until you can stop"
put"3. Pull the emergency brake and steer into the curve."
put"4. Ease off the accelerator, then speed up slightly as you regain more control."
get answer1
if answer1 = 4 then
put "You are correct"
correctanswers := 1 if answer1 = 4 then
else
put "Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 2. When approaching a railway crossing you should :"
put"1. Watch for warning lights that indicate an approaching train."
put"2. Watch for motorcycle riders and cyclists who may slip on the wet tracks."
put"3. Realize that trains always have the right of way."
put"4. All of the above."
get answer2
if answer2 = 4 then
put "You are correct"
correctanswers := 2 if answer2 = 4then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 3. When should you use your car's signals? "
put"1. When changing lanes."
put"2. When turning a corner."
put"3. When pulling out from a line of parked vehicles."
put"4. All of the above."
get answer3
if answer3 = 4 then
put "You are correct"
correctanswers := 3 if answer3 = 4then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 4. When pulling away from the curb, you should: "
put"1. Shoulder check, then pull out when safe."
put"2. Check your rear-view mirror, then pull out when safe."
put"3. Signal, shoulder check, then pull out when safe."
put"4. Signal, check your rear-view mirror, then pull out when safe."
get answer4
if answer4 = 3 then
put "You are correct"
correctanswers := 4 if answer4 = 3then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 5. As you are driving, you should: "
put"1. Keep to the right-hand side of the lane."
put"2. Keep to the left-hand side of the lane."
put"3. Keep to the center of the lane"
put"4. It depends on which lane you are in and the hazards that are around you"
get answer5
if answer5 = 4 then
put "You are correct"
correctanswers := 5 if answer1 = 4then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 6. When approaching a stop sign where there is no stop line, sidewalk or crosswalk you should: "
put"1. Stop 3 metres back from the intersection and inch up slowly."
put"2. Slow down and proceed with caution."
put"3. Stop just before you enter the intersection."
put"4. Stop only if pedestrians are waiting to cross."
get answer6
if answer6 = 3 then
put "You are correct"
correctanswers := 6 if answer1 = 3then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 7. A sign showing a green circle with a straight arrow pointing upwards inside it means: "
put"1. Straight road ahead."
put"2. One lane ahead."
put"3. No turns, drive through only."
put"4. A. and C. are correct."
get answer7
if answer7 = 3 then
put "You are correct"
correctanswers := 7 if answer1 = 3then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 8. At uncontrolled intersections you should always: "
put"1. Come to a complete stop, make sure it is safe and proceed with caution."
put"2. Slow down, make sure it is safe and proceed with caution."
put"3. Stop well before the intersection and inch out slowly; only proceed when no cars are approaching."
put"4. Speed right on through."
get answer8
if answer8 = 2 then
put "You are correct"
correctanswers := 8 if answer8 = 2then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 9. When can you make a right turn at a red light? "
put"1. After slowing down to check for oncoming traffic."
put"2. After coming to a complete stop and yielding to both traffic and pedestrians."
put"3. Anytime there are no signs prohibiting a right turn on a red light."
put"4. B. and C. are correct."
get answer9
if answer9 = 4 then
put "You are correct"
correctanswers := 9 if answer9 = 4then
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
end if
end if
put"Question 10. If someone is tailgating you, you should: "
put"1. Slow down slightly to increase the space in front of your car, allowing you extra space to stop more gradually if you need to"
put"2. Move into another lane."
put"3. Pull over to let the tailgater pass"
put"4. All of the above.."
get answer10
if answer10 = 4 then
correctanswers := 10 if answer1 = 4then
put "You are correct"
put"Thank you, you have finished your driving practice test."
conversion := correctanswers*10
put "For this test you got ", correctanswers ," Correct which is eqaul to ", conversion, " percent"
put "Would you like to Redo this Quiz? (y/n)"
exit when number = "n"
else
put"Sorry you are incorrect or you have not entered one of the following 1-4 numbers."
put"Thank you, you have finished your driving practice test."
end if
end if
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Oct 25, 2007 8:02 pm Post subject: Re: RE:My quiz program : help need |
|
|
NegativeAzn @ Thu Oct 25, 2007 5:11 pm wrote: for some reason wen my correct answers count is always 10, can someone explain why?
Possibly because
code: |
correctanswers := 10
|
you always set it so, if I get just the 10th question correct. Try answering the last question incorrectly on purpose, see what you get then. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|
|