Writing a test in batch code - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Reply
 
Thread Tools Display Modes
 
Old 03-24-2014, 06:41 PM   #1 (permalink)
The Ghost
 
luke127's Avatar
 
Join Date: Mar 2012
Location: Australia
Posts: 858
Default Writing a test in batch code

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.
__________________

__________________
Yeah, I'm the boss 😂😂 FIGJAM 😂😂
luke127 is offline   Reply With Quote
Old 03-24-2014, 06:55 PM   #2 (permalink)
The Ghost
 
luke127's Avatar
 
Join Date: Mar 2012
Location: Australia
Posts: 858
Default Re: Writing a test in batch code

I may try coding this as a multiple choice test using the "CHOICE" command. Perhaps then it may work?
__________________

__________________
Yeah, I'm the boss 😂😂 FIGJAM 😂😂
luke127 is offline   Reply With Quote
Old 03-27-2014, 11:16 AM   #3 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default Re: Writing a test in batch code

what if you created a new variable named correctanswer

and tried to match answer with correctanswer?
office politics is offline   Reply With Quote
Old 03-27-2014, 11:22 AM   #4 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,713
Default Re: Writing a test in batch code

Just a question, but why batch? Why not a higher level language such as C, C++, or C#/Java? Or even PowerShell?
__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Google Pixel XL


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Old 03-27-2014, 12:37 PM   #5 (permalink)
Pushing Daisies on Saturn
 
Yevrag35's Avatar
 
Join Date: Dec 2012
Location: Wisconsin, US
Posts: 1,118
Default Re: Writing a test in batch code

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")
__________________


Yevrag35 is offline   Reply With Quote
Old 03-27-2014, 12:49 PM   #6 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,713
Default Re: Writing a test in batch code

^^^ You must have been bored .
__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Google Pixel XL


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Old 03-27-2014, 12:53 PM   #7 (permalink)
Pushing Daisies on Saturn
 
Yevrag35's Avatar
 
Join Date: Dec 2012
Location: Wisconsin, US
Posts: 1,118
Default Re: Writing a test in batch code

Quote:
Originally Posted by carnageX View Post
^^^ You must have been bored .
And also bored enough to write a version where if you include the word "mom", "mother", or "mutha" in your answer, it denounces your insults...
__________________


Yevrag35 is offline   Reply With Quote
Old 03-31-2014, 01:41 PM   #8 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default Re: Writing a test in batch code

shortcut way is to find a code base to start from. these guys wrote functions for it.

Create a PowerShell Quiz Script - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs
office politics is offline   Reply With Quote
Old 03-31-2014, 02:15 PM   #9 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,713
Default Re: Writing a test in batch code

Quote:
Originally Posted by office politics View Post
shortcut way is to find a code base to start from. these guys wrote functions for it.

Create a PowerShell Quiz Script - Hey, Scripting Guy! Blog - Site Home - TechNet Blogs
This.

Half the time, even in the job, developers will take code from other developers and tweak it to fit their needs.
__________________

__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Google Pixel XL


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing a batch file jm.designs Programming 1 01-07-2011 01:36 PM
Creating a password protected batch file with a batch file MattPwns Programming 2 07-03-2010 05:04 PM
Batch scripting: Startup applications and close batch file LincolnX Microsoft Windows and Software 7 01-17-2008 08:50 PM
Need Batch File code to copy emails alphiemarn Programming 4 10-04-2004 03:13 AM



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 01:43 PM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.