Input confirmation batch file - 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?

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

Related

BATCH Variable Input to Math Subtraction

Very simple question.
I am creating a simple texted based game in batch. It is about you are a pilot for the airline and you need to stop it from crashing into a random variable. Before you "take off" you need to edit your programming terminal and tell it your fuel. The fuel is marked with %fuel%. So when you are in the air. Your Turn will cost you 1000L of Fuel so if I input 54000 i will have 54 turns to get the plane safely landed. The code for the fuel input and display are here I just need the code to have the %fuel% - 1000
:fuel
cls
color c
echo ----------------------------------------
echo FUEL NEEDED FOR FLIGHT
echo ----------------------------------------
echo Awnser in Litres Please
echo eg 54000
echo -----------------------------------------
set /p fuel=""
echo -----------------------------------------
echo Is this Correct Y/N
echo -----------------------------------------
set /p c4=""
if /I "%c4%" EQU "Y" goto :d4
if /I "%c4%" EQU "N" goto :fuel
goto :fuel
:d4
color a
cls
echo ---------------------------------------
echo Flight Navigation System
echo %dep% to %arr%
echo Heading %heading% Degrees
echo ----------------------------------------
echo Captain - %captain%
echo 1st Officer - %officera%
echo 2nd Officer - %officerb%
echo Head Flight Attenedent - %hfa%
echo ----------------------------------------
echo FUEL - %fuel% Litres Remaining
echo ----------------------------------------
pause
Use "Set /a fuel-=1000". If you are using XP you might need to do "Set /a fuel= %fuel%-1000"

Batch program not working

I am new to batch coding and I am having an issue where whenever I select an option, it goes to 1 (which is :MEMBERS) even if I enter 2 or 3. I am unsure why this is happening.
#echo off
cls
color A
:MENU
cls
echo ===============================
echo Mavast Client v0.01
echo ===============================
echo Enter a number from the list and hit enter
echo to run that program.
echo 1. Members
echo 2. Support us
echo 3. Exit
set /p var= Run:
if %var%=="1" goto MEMBERS
if %var%=="2" goto SUPPORT
if %var%=="3" goto EXIT
:MEMBERS
cls
echo Owner/Rifler = C0MpL3T3
echo Admin/Stratcaller = TDGR (The Dutch Grim Reaper)
echo Awper = NONE
echo Lurker = NONE
echo Entry Fragger = NONE
echo press any key to continue
timeout -1 > NUL
goto MENU
:SUPPORT
cls
echo Support us by donating BitCoins or skins
echo to donate skins, just trade them to TDGR or C0MpL3T3.
echo to donate bitcoins, send any amount you want to this address:
echo 1DSRHe7L842MZjwTWYPzgGzbsZ8zU97w9g
echo thank you!
echo press any key to continue
timeout -1 > NUL
goto MENU
:EXIT
cls
exit
try with
if "%var%"=="1" goto MEMBERS
if "%var%"=="2" goto SUPPORT
if "%var%"=="3" goto EXIT
Quotes are also compared in IF conditions.

Error: 1 was unexpected at this time

So I'm making a game based on making decisions using notepad ++ and batch. I'm new to this and I have no idea what the problem is here.
:start
;startup
cls
echo Wine or Cheese?
echo.
echo 1. Wine
echo 2. Cheese
echo 3. Exit
echo.
set /p input0=Enter:
if %input0% equ 1 goto winestart
if %input0% equ 2 goto cheese
if %input0% equ 3 goto exit
When I select winestart or 1, it goes to winestart for a splitsecond then crashes, with the error message: 1 was unexpected at this time.
Winestart looks like this:
:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set p/ input7=Enter:
if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine
/p indicates that the variable is simply set by user input. –
SET
:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set /p input7=Enter:
if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine
[Edit: Correct cure, but no explanation of why the error message appears]
Since input7 is not entered, the if statement is interpreted as
if equ 1 goto redwine
cmd expects if something equ anotherthing dosomething so it sees 1 as the comparison-operator. This is not one of the operators it recognises, so it responds that the 1 is unexpected.
A better form of this is
if /i "%input7%" equ "1" goto redwine
where the /i forces a case-insensitive comparison and "quoting the arguments" preserves the syntax requirement where the user enters nothing or a string containing spaces (you have no control over the user's response.)

Batch File malfunction

This is a few lines from my batch file quiz that I made for friends. I have them answer the question "What topic would you like?" Earlier and they enter John or Computer. I want to be able to use that answer way later in the quiz, and I can't get it to go to a different option for the chosen topic.
So my question is, How can I get the REM to go to the correct topic?
:1
cls
REM Read settings from file
for /f %%S in (topic.ini) do set %%S
if %Mtopic%==John goto John
if %Mtopic%==john goto John
if %Mtopic%==Computer goto Com
if %Mtopic%==computer goto Com
:John
cls
echo.
echo================
echo Is john VERY strange?
echo a.) Yeah.. STRANGE
echo b.) pfft strange? nah.
echo c.) I DONT CARE
echo.
echo================
set /p hi=
if %hi%==a goto crl
if not %hi%==a goto B
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %ll% == y goto J2
if %ll% == Y goto J2
if %ll% == n goto John
if %ll% == N goto John
goto v2lvl2
:J2
cls
echo.
echo Not done.
echo.
pause
goto B
:Com
cls
echo.
echo >>>>>>>>>UPDATE LATER>>>>>>>>>>>
echo.
pause
goto B
I'm not really sure about what you're asking for. Do you mean a piece of code that says something like, "What topic would you like?" and then, depending on what they answered, it would go to either John or Computer?
Then you would simply just use set /p Mtopic=What topic would you like (john/computer) or something to get input and after that you've already got everything done... right? But I feel like I don't really understand your question.

I need a way to prompt a user for an input using batch

I noticed a post on how to make a batch that opens another batch upon an input. However, I need a way that will make the code pause until the correct input is entered, then continue.
So for example, the code would ask what is the access code?
Then the user would input the correct code, for example 123.
Then the code would say "Welcome!"
Then it would execute another question like "What do you want to do today?"
There would be a list of options:
A. Game
B. Browse
C. Nevermind
The user would in put a, b, or c and the script would start either a game or web browser. If the user selected C, then it would exit.
Thanks for the help!
#echo off
echo Welcome!
echo What do you want to do today?
echo.
echo A. Game
echo.
echo B. Browse
echo.
echo C. Nevermind
echo.
choice /C:ABC /N /M "Enter your choice: "
if "%errorlevel%"=="1" goto :game
if "%errorlevel%"=="2" goto :browse
if "%errorlevel%"=="3" goto :nevermind
goto :error
I think a little bit modified version of code should work just fine.
#Echo off
:Start
cls
echo Welcome !
echo To Greet press one.
echo For Goodbye press two.
echo To Abort press 3
ECHO.
ECHO.
SET /p Option=Choice:
if "%Option%"=="1" GOTO Sub_MenuA
if "%Option%"=="2" GOTO Sub_MenuB
if "%Option%"=="3" GOTO Sub_MenuC
if "%Option%"=="quit" GOTO EOF
Goto Start
:Sub_MenuA
echo Hi There!
pause
Goto Start
:Sub_MenuB
echo tatas !
pause
Goto Start
:Sub_MenuC
echo Aborted
Pause
Goto Start
:EOF

Resources