Jeroen Steens
Jeroen Steens

Reputation: 37

Input confirmation batch file

So i was writing a Batch file, and i made a file that you can choose an answer by a question, and its saves it automaticly to a file. But i want to make something before it saves it to a file, to let people confirm their choices. Simplified, i have it like this:

Rem Question 1 appearance
:q1
cls
Echo.
Echo Please select your age:
Echo ==================
Echo A) younger than 18
Echo B) 18-30
Echo C) 30-45
Echo D) older than 45
Echo.
Echo.

Rem Question 1 in- and output settings
:q1.2
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose an age of less than 18. & pause & goto q2
if "%INPUT%"=="B" Echo You chose an age of 18-30. & pause & goto q2
if "%INPUT%"=="C" Echo You chose an age of 30-45. & pause & goto q2
if "%INPUT%"=="D" Echo You chose an age of older than 45. & pause & goto q2
Echo Please enter a valid answer!
goto q1.2

Rem question 2 appearance
:q2
Echo Answer: %INPUT% >>Question1answers.txt
cls
Echo.
Echo Please select your favourite colour:
Echo ==========================
Echo A) Blue
Echo B) Red
Echo C) Green
Echo D) Yellow
Echo E) Other
Echo.
Echo.

Rem Question 2 in- and output settings
:q2.1
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose blue.&pause&goto end
if "%INPUT%"=="B" Echo You chose red.&pause&goto end
if "%INPUT%"=="C" Echo You chose green.&pause&goto end
if "%INPUT%"=="D" Echo You chose yellow.&pause&goto end
if "%INPUT%"=="E" Echo You chose something else.&pause&goto end
Echo Please enter a valid answer!
goto q2.1

So i ask you to not reply with the full code, maybe a little piece so i can learn from it and put it in myself, you know? Thanks!

Edit:

So now i added this part:

:confirmation
cls
Echo Please make sure this is your data:
if "%INPUTT%"=="A" Echo You chose an age of less than 18.
if "%INPUTT%"=="B" Echo You chose an age of 18-30.
if "%INPUTT%"=="C" Echo You chose an age of 30-45.
if "%INPUTT%"=="D" Echo You chose an age of older than 45.
echo.
if "%INPUT%"=="A" Echo You chose blue as your favourite colour.
if "%INPUT%"=="B" Echo You chose red as your favourite colour.
if "%INPUT%"=="C" Echo You chose green as your favourite colour.
if "%INPUT%"=="D" Echo You chose yellow as your favourite colour.
if "%INPUT%"=="E" Echo You chose something else as your favourite colour.

choice /m "Is this your data?" /d Y
if %errorlevel%==1 goto q1

Echo Answer: %INPUTT% >>Question1answers.txt
Echo Answer: %INPUT% >>Question2answers.txt

So i started debugging and when i came to the part it was wrong, it let me through and still saved my input. it kind of ignores the part of if %errorlevel%==1 goto q1 so what do i do now?

Upvotes: 0

Views: 1568

Answers (1)

Stephan
Stephan

Reputation: 56180

since you ask for a short snippet, this should do what you want:

set /p "age=Enter your age: "
choice /M "Your age is %age%, correct?"
if %errorlevel%==1 goto :correct
echo false
goto :eof
:correct
echo true

Upvotes: 1

Related Questions