I'll start with the code:
@echo off
set number=0
echo What would you like to add to %number%
echo 1. Add nothing
echo 2. Add 1
echo 3. Add number of your choosing
set /p test=
:: doesn't add any number
if "%test%" == "1" (
echo You have choosen to not add anything
pause
goto end
)
::Adds number 1 to 0
if "%test%" == "2" (
set /a number=number+1
echo You have added 1 to the number
goto end
)
::Gives choice to add 2 or 3 to number 0
if "%test%" == "3" (
echo Which number would you like to add
echo 1. Number 2
echo 2. Number 3
set /p option=
::Adds 2 to 0
if "!option!" == "1"(
echo You have added 2 to the number
set /a number=number+2
pause
)
::Adds 3 to 0
if "!option!" == "2"(
echo You have added 3 to the number
set /a number=number+3
pause
)
goto end
)
:end
echo Your number is %number%
pause
This states the number as 0, and then gives you an option to add 0, 1, 2 or 3 to the number 0. I've done it this way so I can test out having an If statements inside of an if statement that asks for an input but I'm lost.
Adding 0 or 1 to number works fine, but as soon as you choose option 3 (wanting to add 2 or 3) it crashes.
I get the error: The syntax of the command is incorrect
I'm guessing it's a silly mistake, if you could point it out, that would be perfect.
Aucun commentaire:
Enregistrer un commentaire