-2

I'm having to do a project on figurative language in Maroon 5 music, and decided to make a quiz. I am trying to be able to count how many questions were right. Here is my work so far, and there is a bug somewhere, but I don't know what it is.

@echo off
color 0f
:START
set Q=Q
cls
echo Maroon 5 Figuratve Language
echo ---------------------------
echo Options (Type a number and press ENTER):
echo 1) Take quiz
echo 2) Change color scheme
set /p Choice= 
if %Choice% == 1 GOTO GAME
if %Choice% == 2 GOTO COLOR
:COLOR
cls
echo Choose a color scheme.
echo 1) Black BG, White text
echo 2) White BG, black text
set /p color= 
if %color% == 1 GOTO 0F
if %color% == 2 GOTO F0
:0F
color 0f
GOTO start
:F0
color f0
GOTO start
:GAME
set qr=0
cls
goto Q1
:Q1
set qn=1
cls
echo What type of figurative language is "I can smell your scent from miles?"
echo a) Simile
echo b) Hyperbole
echo c) Metaphor
echo d) Personification
set /p Q1=
if %Q1% == b goto CORRECT
if NOT %Q1% == b goto INCORRECT
:CORRECT
set /a qr=%qr%+1
set /a qn=%qn%+1
goto %Q%%qn%
:INCORRECT
cls
echo Incorrect...
pause
set /a qn=%qn%+1
goto %Q%%qn%
:Q2
echo testing
echo %qn%
echo %qr%
pause

1 Answers1

0

I can see a bug (there might be more in the code but this one is the first I can see ^^)! :D It's in the line goto %Q%%qn%. I've answered a similar question time ago: How to put variable value inside another variable name in batch?

The point is that as your variables are being evaluated at parse time the interpreter doesn't know what's the value of %Q% and %qn%. You have to add SETLOCAL EnableDelayedExpansion at the beginning of your script and surround your variables with !...! instead of %...%. This will force the interpreter to evaluate the values at run time considering any changes made to the variables so far.

Community
  • 1
  • 1
MichaelS
  • 5,941
  • 6
  • 31
  • 46