Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27569

VS 2010 Using Console to write Quiz Program. Please help if you can. Thank you.

$
0
0
Hello to you all,

I am a new member to this site and a "total newbie" to VB.net. This is my first year doing this and this is also my first post so please be gentle.

This is an assignment I have to complete where I have to write a program for a multiple choice quiz consisting of 10 questions using console on Visual Studio 2010. I have made an attempt at writing this but I have come as far as I can go with it. I "think" I am not too far away but would appreciate your advice on where I might be going wrong.

This is a copy of my assignment first of all:

Use of Sub and Function Procedures (Parallel Arrays)

Using sub and function procedures write software to allow users to take a simple multiple choice test comprising of 10 questions.

Create the following arrays: Array of Questions
4 Arrays of Possible Answers
Array of Correct Answers ie, B, C, D, D, A, etc

Sample Question .

Question : How many wheels on a car?

A. 3 B. 4 C. 5 D. 6

Ans (A, B, C, D or X)

(NB: X implies No Answer/Don’t know)


After each test output the following table :

Question No Correct Answer User Answer
1 B C
2 C A
3 D B
4 D B
5 A X
Etc

• The number of Correct answers
• The Number of Incorrect Answers
• The Number of Question not Answered ( No of X’s)

Set and apply a Simple Grading Criteria of (Fail, Pass, Merit and Distinction)


The following is now the code I have done so far. My first problem occurs when it comes to answering the questions. If I type "C" for my first answer for example the letter "C" then remains in the area where I place my next answer and I am unable to delete it. This occurs throughout the rest of the questions.

Also, when it comes to the end of the test my answers will not display properly in my table.

I am really stuck with this and would appreciate any help or guidance. Many thanks in advance.

vbnewbie007

Option Explicit On
Imports System.Console

Module module1

'THROUGH THE USE OF SUB AND FUNCTION PROCEDURES THE FOLLOWING PROGRAM WILL ALLOW USERS TO TAKE A SIMPLE
'MULTIPLE CHOICE TEST COMPRISING OF TEN QUESTIONS.

'DECLARATION OF VARIABLES

Dim Question(9) As String 'THIS IS THE QUESTION THAT IS BEING ASKED
Dim QuestNo As Integer 'THIS IS THE QUESTION NUMBER THAT IS BEING ASKED

Dim answerA(9) As String 'THIS IS POSSIBLE ANSWER 'A' THAT WILL BE DISPLAYED TO THE USER
Dim answerB(9) As String 'THIS IS POSSIBLE ANSWER 'B' THAT WILL BE DISPLAYED TO THE USER
Dim answerC(9) As String 'THIS IS POSSIBLE ANSWER 'C' THAT WILL BE DISPLAYED TO THE USER
Dim answerD(9) As String 'THIS IS POSSIBLE ANSWER 'D' THAT WILL BE DISPLAYED TO THE USER
Dim CorAns(9) As String 'THIS IS THE CORRECT ANSWER FOR EACH QUESTION

Dim Answer(9) As String 'THIS IS THE ANSWER THE USER WILL BE GIVING FOR EACH QUESTION ASKED
Dim NumCor As Integer 'THIS IS THE NUMBER OF CORRECT ANSWERS SUBMITTED BY THE USER
Dim IncAns As Integer 'THIS IS THE NUMBER OF INCORRECT ANSWERS SUBMITTED BY THE USER
Dim UnansQ As Integer 'THIS IS THE NUMBER OF QUESTIONS THE USER DID NOT ANSWER i.e. SELECTED "X"
Dim Grade As String 'THIS IS THE FINAL GRADE AWARDED TO THE USER DEPENDING ON SCORE ACHIEVED

Sub main()

loadQuestions()
displayTitles()
QuestNo = 0
processAnswers()
calculateGrade()

End Sub

Sub processAnswers()

For x = 0 To 9

If Answer(QuestNo).ToUpper = CorAns(x).ToUpper Then
NumCor += 1

End If

If Answer(QuestNo).ToUpper = "x".ToUpper Then
UnansQ += 1

Else : IncAns += 1

End If

Next

End Sub

'PROCESSES

'HERE I WILL BE PROCESSING THE ANSWERS SUBMITTED BY THE USER AND ALLOCATING A GRADE DEPENDING ON
'NUMBER OF CORRECT ANSWERS ACHIEVED.

Sub calculateGrade()

For x = 0 To 9

If NumCor <= 3 Then
Grade = "FAIL"

If NumCor <= 5 Then
Grade = "PASS"

If NumCor <= 7 Then
Grade = "MERIT"

If NumCor <= 10 Then
Grade = "DISTINCTION"

End If
End If
End If
End If

Next

'OUPUTS

'THIS IS WHERE THE RESULTS OF THE TEST WILL BE DISPLAYED IN A TABLE SHOWING QUESTION NUMBER, CORRECT ANSWER AND USER ANSWER.
'A SUMMARY WILL ALSO BE SHOWN BELOW THE TABLE GIVING NUMBER OF CORRECT ANSWERS, INCORRECT ANSWERS AND QUESTIONS NOT
'ANSWERED. THE USER WILL ALSO BE GIVEN A GRADE I.E. PASS, FAIL, MERIT OR DISTINCTION.

For x = 0 To 9

Clear()
WriteLine()
WriteLine()
WriteLine(" QUESTION NUMBER CORRECT ANSWER USER ANSWER")
WriteLine()
WriteLine(" {0} {1} {2}", QuestNo, CorAns(x), Answer(x))
WriteLine()
WriteLine()
WriteLine("******************************************************************")


WriteLine()
WriteLine()
WriteLine("NUMBER OF CORRECT ANSWERS {0}", NumCor)
WriteLine()
WriteLine()
WriteLine("NUMBER OF INCORRECT ANSWERS {0}", IncAns)
WriteLine()
WriteLine()
WriteLine("NUMBER OF QUESTIONS NOT ANSWERED {0}", UnansQ)
WriteLine()
WriteLine()
WriteLine("GRADE AWARDED: {0}", Grade)
WriteLine()
WriteLine("0-3 ANSWERS CORRECT = FAIL")
WriteLine("4-5 ANSWERS CORRECT = PASS")
WriteLine("6-7 ANSWERS CORRECT = MERIT")
WriteLine("8-10 ANSWERS CORRECT = DISTINCTION")
WriteLine()
WriteLine()
WriteLine()
Write("Press any key to exit test")
ReadKey()

Next

End Sub

Sub displayTitles()

'SCREEN DISPLAY

'THIS WILL BE THE WELCOME SCREEN THE USER IS GREETED WITH WHEN THE PROGRAM IS RUN.

Console.ForegroundColor = ConsoleColor.Green
Console.BackgroundColor = ConsoleColor.DarkRed
Clear()

WriteLine("*******************************************************************************")
WriteLine("* *")
WriteLine("* *")
WriteLine("* PROGRAM TO ALLOW USERS TO TAKE A SIMPLE *")
WriteLine("* MULTIPLE CHOICE TEST COMPRISING OF *")
WriteLine("* 10 QUESTIONS *")
WriteLine("* *")
WriteLine("* PROGRAM WRITTEN BY xxxxx xxxxxx *")
WriteLine("* ON xx/xx/2013 *")
WriteLine("* *")
WriteLine("* *")
WriteLine("*******************************************************************************")

Write(" Press any key to continue...")
ReadKey()

'INPUTS

'HERE I WILL BE ISSUING INSTRUCTIONS TO THE USER ON HOW TO TAKE THE QUIZ AND PROMPTING THEM TO
'PRESS ANY KEY WHEN THEY ARE READY TO BEGIN THE TEST.

Clear()

WriteLine("YOU WILL NOW BE GIVEN 10 MULTIPLE CHOICE QUESTIONS")
WriteLine()
WriteLine("PLEASE SELECT EITHER A, B, C OR D AS YOUR ANSWER")
WriteLine()
WriteLine("IF YOU ARE UNSURE OF THE ANSWER PLEASE SELECT 'X'")
WriteLine()
WriteLine()
WriteLine()
Write(" Press any key to begin the test when you are ready...")
ReadKey()

Clear()

DisplayQuestion()

End Sub

Sub DisplayQuestion()

Do
WriteLine()
WriteLine()

WriteLine()

Write("{0}", Question(QuestNo))
WriteLine()
WriteLine()
Write("IS THE ANSWER:")
WriteLine()
WriteLine()
WriteLine("{0}", answerA(QuestNo))
WriteLine()
WriteLine("{0}", answerB(QuestNo))
WriteLine()
WriteLine("{0}", answerC(QuestNo))
WriteLine()
WriteLine("{0}", answerD(QuestNo))
WriteLine()
WriteLine()
Write("YOUR ANSWER: {0}", Answer)
Answer(QuestNo) = ReadLine()
Clear()
WriteLine()
WriteLine()
QuestNo += 1

Loop Until QuestNo = 10

End Sub

Sub loadQuestions()

'HERE I HAVE PLACED MY LIST OF 10 QUESTIONS PLUS CORRECT ANSWERS INTO IT'S OWN SUB:

WriteLine()
Question(0) = "Q1: According to the proverb, what is the pot calling the kettle?"

WriteLine()
answerA(0) = "A). Hot"
answerB(0) = "B). Noisy"
answerC(0) = "C). Black"
answerD(0) = "D). My hero"

CorAns(0) = "C"

WriteLine()
Question(1) = "Q2: According to the old saying, 'Don't throw the baby out with the' what?"
WriteLine()
answerA(1) = "A). Rubbish"
answerB(1) = "B). Nappies"
answerC(1) = "C). Pram"
answerD(1) = "D). Bathwater"

CorAns(1) = "D"

WriteLine()
Question(2) = "Q3: According to a proverb about hope, 'There's always a light at the end of' what?"
WriteLine()
answerA(2) = "A). The journey"
answerB(2) = "B). The day"
answerC(2) = "C). The tunnel"
answerD(2) = "D). E.T.'s finger"

CorAns(2) = "C"

WriteLine()
Question(3) = "Q4: Which of these gambling games requires a pair of dice?"
WriteLine()
answerA(3) = "A). Craps"
answerB(3) = "B). Roulette"
answerC(3) = "C). Poker"
answerD(3) = "D). Blackjack"

CorAns(3) = "A"

WriteLine()
Question(4) = "Q5: What kind of animal traditionally lives in a sty?"
WriteLine()
answerA(4) = "A). Cow"
answerB(4) = "B). Pig"
answerC(4) = "C). Fox"
answerD(4) = "D). Teenager"

CorAns(4) = "B"

WriteLine()
Question(5) = "Q6: What piece of advice most often follows 'If at first you don't succeed'?"
WriteLine()
answerA(5) = "A). Throw in the towel"
answerB(5) = "B). File an appeal"
answerC(5) = "C). Talk to James"
answerD(5) = "D). Try, try again"

CorAns(5) = "D"

WriteLine()
Question(6) = "Q7: If something sets your 'blood boiling,' what word best describes your attitude?"
WriteLine()
answerA(6) = "A). Enraged"
answerB(6) = "B). Mournful"
answerC(6) = "C). Joyous"
answerD(6) = "D). Eager"

CorAns(6) = "A"

WriteLine()
Question(7) = "Q8: Which of these fruits doesn't grow on a tree?"
WriteLine()
answerA(7) = "A). Apple"
answerB(7) = "B). Orange"
answerC(7) = "C). Grape"
answerD(7) = "D). Peach"

CorAns(7) = "C"

WriteLine()
Question(8) = "Q9: What is the main ingredient in a traditional hamburger?"
WriteLine()
answerA(8) = "A). Ham"
answerB(8) = "B). Beef"
answerC(8) = "C). Veal"
answerD(8) = "D). Spam"

CorAns(8) = "A"

WriteLine()
Question(9) = "Q10: Italy's shape is said to resemble what object?"
WriteLine()
answerA(9) = "A). Boot"
answerB(9) = "B). Cup"
answerC(9) = "C). Flag"
answerD(9) = "D). Pizza"

CorAns(9) = "A"

End Sub

End Module

Viewing all articles
Browse latest Browse all 27569

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>