Recent Articles
Check Out
- Tech Today
- and our
- Computer Tutorials
- or join the discussion @ our
- Computer Forum
Search Articles
How to make a Quiz in Batch
Jan 16 2012 04:19 PM | Betrayal in Programming Tutorials
Hello, in this tutorial, I will be teaching you how to make a simple Quiz application coding in Batch. If you are new or don't know what Batch is, go to my first tutorial titled Basics to Batch Coding.
In this article, we are going to make a simple quiz using Batch. To start off, let's make an introductory page:
Now then, why don't I explain the code?
1. We start out with @echo off which you should put at the start of every code.
2. Next we create a loop :INTRODUCTION
3. Afterwards, we use the echo command to create some lines of text and putting a period after echo makes an empty line.
4. Lastly we create a input using the set/p input command. The stuff after the "=" can be changed to anything. That line gives the user a place to type their Command.
5. We use an if-statement to retrieve input and execute a command from there. if%input% = 1 goto QUIZ
Currently, the program won't do anything since we have to create a loop for the QUIZ! For both inputs, the program will shutdown since their is no basis for them, except for input 2 which shuts down anyways.
Moving on..!
Now then, shall I explain.
*Also, despite the length of this code, Batch coding is intended to be easy and it really is. I'd say it's like HTML but a programming language, it's on that level. Batch can be used to do many things for you like create folders, open websites or images, etc. Anyway, back to the program.
1. We created a :QUIZ loop which starts the Quiz.
2. We used the echo and set/p input commands to create a method of reading the question and selecting an answer.
3. We included :WRONG loop to let the client know where to go if they answer the question wrong. This loop will return them back to the main menu if they click on any key.
4. Next we have to create a code that shows the client that they've won the game.
Now then, I'm sure you can create a loop for the Winner screen, or you can even use the start command and create another document to show the winning screen. You could do...
start Winner.txt or start Winner.png
In the final product, I will just use the echo command to tell the client that they've won the game.
Your Code should look like this:
In this article, we are going to make a simple quiz using Batch. To start off, let's make an introductory page:
@echo off
title Computer Knowledge Quiz
:INTRODUCTION
echo Welcome to this simple Computer Knowledge quiz game!
echo.
echo.
echo To start the Quiz, type 1 and press Enter!
echo To quit the game, type 2 and press Enter!
echo.
set /p input=Which Command?
if %input% = 1 goto QUIZ
if %input% = 2 exit
Now then, why don't I explain the code?
1. We start out with @echo off which you should put at the start of every code.
2. Next we create a loop :INTRODUCTION
3. Afterwards, we use the echo command to create some lines of text and putting a period after echo makes an empty line.
4. Lastly we create a input using the set/p input command. The stuff after the "=" can be changed to anything. That line gives the user a place to type their Command.
5. We use an if-statement to retrieve input and execute a command from there. if%input% = 1 goto QUIZ
Currently, the program won't do anything since we have to create a loop for the QUIZ! For both inputs, the program will shutdown since their is no basis for them, except for input 2 which shuts down anyways.
Moving on..!
@echo off
title Computer Knowledge Quiz
:INTRODUCTION
echo Welcome to this simple Computer Knowledge quiz game!
echo.
echo.
echo To start the Quiz, type 1 and press Enter!
echo To quit the game, type 2 and press Enter!
echo.
set /p input=Which Command?
if %input% == 1 goto :QUIZ
if %input% == 2 exit
:QUIZ
echo What is a basic input device using a Computer?
echo A. Monitor
echo B. Keyboard
echo C. Printer
echo D. Speakers
set /p input=Your Answer?
if %input% == B goto :2
goto :WRONG
:WRONG
echo Sorry, but that is incorrect. Press any key to return to the main screen.
pause
goto :INTRODUCTION
:2
echo What is a basic output device using a Computer?
echo A. Monitor
echo B. Keyboard
echo C. Scanner
echo D. Flash Drive
set /p input=Your Answer?
if %input% == A goto :3
goto :WRONG
:3
echo Which of the following is not an Operating System?
echo A. Windows 7
echo B. Ubuntu
echo C. Mac OS X
echo D. DOS XO
set /p input=Your Answer?
if %input% == D goto :Winner
goto :WRONG
Now then, shall I explain.
*Also, despite the length of this code, Batch coding is intended to be easy and it really is. I'd say it's like HTML but a programming language, it's on that level. Batch can be used to do many things for you like create folders, open websites or images, etc. Anyway, back to the program.
1. We created a :QUIZ loop which starts the Quiz.
2. We used the echo and set/p input commands to create a method of reading the question and selecting an answer.
3. We included :WRONG loop to let the client know where to go if they answer the question wrong. This loop will return them back to the main menu if they click on any key.
4. Next we have to create a code that shows the client that they've won the game.
Now then, I'm sure you can create a loop for the Winner screen, or you can even use the start command and create another document to show the winning screen. You could do...
start Winner.txt or start Winner.png
In the final product, I will just use the echo command to tell the client that they've won the game.
Your Code should look like this:
@echo off
title Computer Knowledge Quiz
:INTRODUCTION
echo Welcome to this simple Computer Knowledge quiz game!
echo.
echo.
echo To start the Quiz, type 1 and press Enter!
echo To quit the game, type 2 and press Enter!
echo.
set /p input=Which Command?
if %input% == 1 goto :QUIZ
if %input% == 2 exit
:QUIZ
echo What is a basic input device using a Computer?
echo A. Monitor
echo B. Keyboard
echo C. Printer
echo D. Speakers
set /p input=Your Answer?
if %input% == B goto :2
goto :WRONG
:WRONG
echo Sorry, but that is incorrect. Press any key to return to the main screen.
pause
goto :INTRODUCTION
:2
echo What is a basic output device using a Computer?
echo A. Monitor
echo B. Keyboard
echo C. Scanner
echo D. Flash Drive
set /p input=Your Answer?
if %input% == A goto :3
goto :WRONG
:3
echo Which of the following is not an Operating System?
echo A. Windows 7
echo B. Ubuntu
echo C. Mac OS X
echo D. DOS XO
set /p input=Your Answer?
if %input% == D goto :Winner
goto :WRONG
:Winner
echo.
echo You have WON the game! Pat yourself on the back!
pause











0 Comments