I am having trouble creating a loop that will continue this script until all questions have been answered correctly. Yes, I’m still a student and I’m pretty bad at loops so far. If any one has any ideas I would appreciate hearing them. Thanks
Script Name:Math Quiz Module 7
Version:
Author:Michael Coffey
Date:11/19/2013
Description:
#Clear the windows console
Clear-Host
Define the variables used in this script to store players answers
$question1 = “”
$question2 = “”
$question3 = “”
$question4 = “”
$question5 = “”
Define a variable to keep track of the number of correct answers
quiz questions
$nocorrect = 0
Display games opening screen
Write-Host “n
nn
nt
t " WELCOME TO THE MATH QUIZ.”"
Write-Host
Write-Host “n
nn
tt
t “By Michael Coffey””
Write-Host “n
nn
nn
nn
nn
n “Press Enter To continue:””
#Pause script execution until player presses enter key
Read-Host
#Clear the windows console screen
Clear-Host
Provide instruction for player
write-host “n
n The Math Quiz will test your knowledge of basic Math Skillsn" Write-host " The Quiz Has Five Questions
n”
Write-Host " At The end Of The Quiz You Will Be Assigned A Rankn" Write-Host " Based On The Number Of Correct Answers
n"
Write-Host " Score: 5 Correct = Einstien (Expert)"
Write-Host “t
t 4 Correct = CPA”
Write-Host “t
t 3 Correct = You Can Balance A Checkbook”
Write-Host “t
t 2 Correct = Better Use A debit Card”
Write-Host “t
t 1 Correct = Always Have Exact Change”
Write-Host “t
t 0 Correct = Have Someone Else Handle Your Money”
Write-Host “n
nn
n Press Enter To Continue”
#Pause script and wait for player input
Read-Host
#Ask the first question
while (($question1 -ne “a”)-and ($question1 -ne “b”)`
-and($question1 -ne “c”) -and ($question1 -ne “d”))
{
Clear-Host # Clear the windows console
Write-Host
Write-Host " What is the sum of 2+2?"
Write-Host
Write-Host " A. 22"
Write-Host " B. 4 "
Write-Host " C. 12 "
Write-host " D. 75"
Write-Host
$question1 = Read-Host “Type The Letter Of The Correct Answer And Press The Enter Key”
}
Clear the windows console
Clear-host
#Ask the second question
while (($question2 -ne “a”)-and ($question2 -ne “b”)`
-and($question2 -ne “c”) -and ($question2 -ne “d”))
{
Clear-Host # Clear the windows console
Write-Host
Write-Host " What is 10 multiplied by 10?"
Write-Host
Write-Host " A. 1010"
Write-Host " B. 1100 "
Write-Host " C. 100 "
Write-host " D. 0011"
Write-Host
$question2 = Read-Host “Type The Letter Of The Correct Answer And Press The Enter Key”
}
Clear the windows console
Clear-host
#Ask the third question
while (($question3 -ne “a”)-and ($question3 -ne “b”)`
-and($question3 -ne “c”) -and ($question3 -ne “d”))
{
Clear-Host # Clear the windows console
Write-Host
Write-Host " What is the square root Of 9?"
Write-Host
Write-Host " A. 3"
Write-Host " B. 99 "
Write-Host " C. 33 "
Write-host " D. Roots grow on Trees"
Write-Host
$question3 = Read-Host “Type The Letter Of The Correct Answer And Press The Enter Key”
}
Clear the windows console
Clear-host
#Ask the fourth question
while (($question4 -ne “a”)-and ($question4 -ne “b”)`
-and($question4 -ne “c”) -and ($question4 -ne “d”))
{
Clear-Host # Clear the windows console
Write-Host
Write-Host " What is the value of Pi?"
Write-Host
Write-Host " A. 3.14"
Write-Host " B. 1/8 "
Write-Host " C. Cherry "
Write-host " D. 31.4"
Write-Host
$question4 = Read-Host “Type The Letter Of The Correct Answer And Press The Enter Key”
}
Clear the windows console
Clear-host
#Ask the fifth question
while (($question5 -ne “a”)-and ($question5 -ne “b”)`
-and($question5 -ne “c”) -and ($question5 -ne “d”))
{
Clear-Host # Clear the windows console
Write-Host
Write-Host " What 1000 divided by 100?"
Write-Host
Write-Host " A. 10000"
Write-Host " B. 10 "
Write-Host " C. 100 "
Write-host " D. 150"
Write-Host
$question5 = Read-Host “Type The Letter Of The Correct Answer And Press The Enter Key”
}
#Clear the windows console
Clear-host
Write-host
Write-host " Press the Enter Key to get your score."
#pause script
Read-host
#Clear the windows console screen
Clear-host
#Grade the quiz
if ($question1 -eq “B”) {$noCorrect++} # Correct answer B
if ($question2 -eq “C”) {$noCorrect++} # Correct answer C
if ($question3 -eq “A”) {$noCorrect++} # Correct answer A
if ($question4 -eq “A”) {$noCorrect++} # Correct answer A
if ($question5 -eq “B”) {$noCorrect++} # Correct answer B
#Assign a rank based on correct answers
if ($noCorrect -eq 0){
write-host
write-host " You did not answer any questions correctly."
Write-host
Write-host " You should let someone else handle your money."
}
if ($noCorrect -eq 1){
write-host
write-host " You answered one question correctly."
Write-host
Write-host " You should always have exact change."
}
if ($noCorrect -eq 2){
write-host
write-host " You answered two question correctly."
Write-host
Write-host " You should use a debit card."
}
if ($noCorrect -eq 3){
write-host
write-host " You answered three question correctly."
Write-host
Write-host " You can balance a checkbook."
}
if ($noCorrect -eq 4){
write-host
write-host " You answered four question correctly."
Write-host
Write-host " You might be a CPA."
}
if ($noCorrect -eq 5){
write-host
write-host " You answered five question correctly."
Write-host
Write-host " You are as smart as Einstien."
}