Writing a test in batch code

luke127

The Ghost
Messages
868
Location
Australia
Ok so the title says it all. I want to write a test in batch coding.

I've succeeded so far in creating the questions, but the console keeps processing the answers as if they were commands and not simply a string variable.

Anyone know how to fix this? Here's the code:

Code:
cls
@ECHO OFF
COLOR 02
goto QUESTIONS
:FAIL
echo One of your questions was incorrect, please redo the test.
:QUESTIONS
echo TREE Questions
echo Question 1: How would you show the folders inside the drive F: (Using the TREE command)
set /p "answer=>"
if NOT %answer%== "TREE F:" goto FAIL
echo Question 2: How would you show the files AND folders inside the drive F:
set/p "answer"=>"
if NOT %answer%== "TREE F: /f" goto FAIL
echo MKDIR Usage
echo How would you create a folder named Important inside drive F:
set/p "answer=>"
if NOT "%answer%"== "MKDIR F:\Important"
:END
echo Congratulations you have finished the test! 
pause
More questions will be added to the script as I work.
 
Just a question, but why batch? Why not a higher level language such as C, C++, or C#/Java? Or even PowerShell?
 
BORED!!!! Take! Powershell! Script! NOW!
Code:
#Variables
$quest1 = "How would you show the folders inside the drive F: (Using the TREE command)?"
$quest2 = "How would you show the files AND folders inside the drive F:?"
$quest3 = "How would you create a folder named 'Important' inside drive F:?"
$wrong = "That answer was incorrect, please try again."
$right = "Correct!"
$ans1 = "TREE F:"
$ans2 = "TREE F: /f"
$ans3 = "MKDIR F:\Important"

do {
Clear-Host
#Question 1

    Write ""
    Write-Host "---- Question 1 ----"
    Write-Host $quest1
    do {
    Write ""
    $input1 = (Read-Host "Answer=>")
    if ($input1 -ne $ans1)
        {
        Write ""
        Write-Host $wrong
        }
    else
        {
        Clear-Host
        Write ""
        Write-Host $right
        }
    } until ($input1 -eq $ans1)
#Question 2

    Write ""
    Write-Host "---- Question 2 ----"
    Write $quest2
    do {
    Write ""
    $input2 = (Read-Host "Answer=>")
    if ($input2 -ne $ans2)
        {
        Write ""
        Write-Host $wrong
        }
    else
        {
        Clear-Host
        Write ""
        Write-Host $right
        }
    } until ($input2 -eq $ans2)
#Question 3

    Write ""
    Write-Host "---- Question 3 ----"
    Write-Host $quest3
    do {
    Write ""
    $input3 = (Read-Host "Answer=>")
    if ($input3 -ne $ans3)
        {
        Write ""
        Write-Host $wrong
        }
    else
        {
        Clear-Host
        Write ""
        Write-Host $right
        }
    } until ($input3 -eq $ans3)

#End of Test Procedure
Write ""
Write-Host "You've succesfully completed with correct answers!"
Write ""
$exit = (Read-Host "Press x to exit the session, or Enter to repeat")
} until ($exit -eq "x")
 
Back
Top Bottom