how to record answers in batch game

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
new2batch
Posts: 3
Joined: 30 May 2011 14:50

how to record answers in batch game

#1 Post by new2batch » 30 May 2011 14:56

Hi, I am new to batch scripting and was wondering if anyone could explain to me how to record an input. I want the script on input of answer to record whether it was right or wrong and how many answers the user got right and wrong. It is for a simple quiz game obviously

Does anyone know of any good beginner resources?

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: how to record answers in batch game

#2 Post by orange_batch » 30 May 2011 15:00

This may look complex for a total beginner, but it's definitely not. Study up!

Code: Select all

@echo off
set /p "variable=What's your input?: "
if /i "%variable%"=="answer" (echo:Correct.&set /a counter+=1) else echo:Incorrect.
echo:Number of questions correct: %counter%


Resources:
http://ss64.com/nt/syntax.html
http://ss64.com/nt/

new2batch
Posts: 3
Joined: 30 May 2011 14:50

Re: how to record answers in batch game

#3 Post by new2batch » 30 May 2011 15:13

ill toy around with it, im trying to learn what it all means and how it is used.

I think i understand it a bit though. Ill let you know how it works

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: how to record answers in batch game

#4 Post by nitt » 30 May 2011 15:18

new2batch wrote:ill toy around with it, im trying to learn what it all means and how it is used.

I think i understand it a bit though. Ill let you know how it works


Ya, do what he said.

set var=dog

Sets the variable "var" to "dog". But

"set /p var=dog"

Sets var equal to whatever you type in, but it shows "dog" on the same line you have to type it in. So you'd want something like:

Code: Select all

@echo off
echo What was a famous historical war that could have been prevented if there wasn't a lack of communication?
set /p answer=The War of:
if "%answer%" EQU "1812" echo You are correct!
if "%answer%" NEQ "1812" echo You're an idiot...
pause

new2batch
Posts: 3
Joined: 30 May 2011 14:50

Re: how to record answers in batch game

#5 Post by new2batch » 30 May 2011 17:04

I tried using the code that was added above for the counter and it didnt work. could it have something to do with the version of dos im using? ( using windows vista os )

Im confused on the arithmetic and counting functions. As a layperson its hard to decipher the lingo used. Anyone have any extremely simple program that illustrates these functions.

I ended up changing the script so it would just loop back to the question til the right input was entered, this is probably more valuable as a studying tool. However if anyone can help me understand it it would be most appreciated.

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: how to record answers in batch game

#6 Post by nitt » 30 May 2011 17:15

new2batch wrote:I tried using the code that was added above for the counter and it didnt work. could it have something to do with the version of dos im using? ( using windows vista os )

Im confused on the arithmetic and counting functions. As a layperson its hard to decipher the lingo used. Anyone have any extremely simple program that illustrates these functions.

I ended up changing the script so it would just loop back to the question til the right input was entered, this is probably more valuable as a studying tool. However if anyone can help me understand it it would be most appreciated.


No, it should work on all OS.

He's using a more professional way. Let me try and simplify it for you.

Code: Select all

@echo off
set counter=0

set /p variable=What's your input?:
if "%variable%" EQU "answer" (
echo Correct
set /a counter=%counter%+1
) else (
echo Incorrect.
)

set /p variable=What's your input?:

if "%variable%" EQU "answer" (
echo Correct
set /a counter=%counter%+1
) else (
echo Incorrect.
)

echo Number of questions correct: %counter%
pause


Try that. If you copy it correctly, it should work.

Post Reply