Batch file help

Watchylol

Estimable
Jan 29, 2015
2
0
4,510
0
Im currently creating a lottery but there's something wrong about the code i just can't spot the sollution. No matter what i write in the size of people attending it only gives me the opportunity to chose between the numbers 1-2. Here's the code:
@echo off
set /p ipa=Select a size of people attending 2-30:
if %ipa%==2 goto START 2;
if %ipa%==3 goto START 3;
if %ipa%==4 goto START 4;
if %ipa%==5 goto START 5;
if %ipa%==6 goto START 6;
if %ipa%==7 goto START 7;
if %ipa%==8 goto START 8;
if %ipa%==9 goto START 9;
if %ipa%==10 goto START 10;
if %ipa%==11 goto START 11;
if %ipa%==12 goto START 12;
if %ipa%==13 goto START 13;
if %ipa%==14 goto START 14;
if %ipa%==15 goto START 15;
if %ipa%==16 goto START 16;
if %ipa%==17 goto START 17;
if %ipa%==18 goto START 18;
if %ipa%==19 goto START 19;
if %ipa%==20 goto START 20;
if %ipa%==21 goto START 21;
if %ipa%==22 goto START 22;
if %ipa%==23 goto START 23;
if %ipa%==24 goto START 24;
if %ipa%==25 goto START 25;
if %ipa%==26 goto START 26;
if %ipa%==27 goto START 27;
if %ipa%==28 goto START 28;
if %ipa%==29 goto START 29;
if %ipa%==30 goto START 30;
:START 2
set /p input=Select a number between 1-2:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
echo %input% is Not Valid!
pause;
:START 3
set /p input=Select a number between 1-3:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
if %input%==3 goto You lost;
echo %input% is Not Valid!
pause;
:START 4
set /p input=Select a number between 1-4:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
if %input%==3 goto You lost;
if %input%==4 goto You lost;
echo %input% is Not Valid!
pause;
echo %input% is Not Valid!
:START 5
set /p input=Select a number between 1-5:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
if %input%==3 goto You lost;
if %input%==4 goto You lost;
if %input%==5 goto You lost;
pause;
echo %input% is Not Valid!
:START 6
set /p input=Select a number between 1-6:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
if %input%==3 goto You lost;
if %input%==4 goto You lost;
if %input%==5 goto You lost;
if %input%==6 goto You lost;
pause;
echo %input% is Not Valid!
:START 7
set /p input=Select a number between 1-7:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
if %input%==3 goto You lost;
if %input%==4 goto You lost;
if %input%==5 goto You lost;
if %input%==6 goto You lost;
if %input%==7 goto You lost;
pause;
echo %input% is Not Valid!
:START 8
set /p input=Select a number between 1-8:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
if %input%==3 goto You lost;
if %input%==4 goto You lost;
if %input%==5 goto You lost;
if %input%==6 goto You lost;
if %input%==7 goto You lost;
if %input%==8 goto You lost;
pause;
echo %input% is Not Valid!
:START 9
set /p input=Select a number between 1-9:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
if %input%==3 goto You lost;
if %input%==4 goto You lost;
if %input%==5 goto You lost;
if %input%==6 goto You lost;
if %input%==7 goto You lost;
if %input%==8 goto You lost;
if %input%==9 goto You lost;
pause;
echo %input% is Not Valid!
: PRIZE
echo YOU WON!
pause;
:You lost
echo That wasn't the right number. Try again!
goto START 5
pause;
 

JeckeL

Distinguished
Jul 19, 2009
224
1
18,910
41
Because of the space in your goto labels it is just seeing them all as:

if %ipa%==2 goto START
if %ipa%==3 goto START
if %ipa%==4 goto START
So it just goes to the first "START" goto in the code which is the one for the 1-2 choice. If you want to use goto labels with spaces you'll either need to put quotations/apostrophes around them or just not use any spaces

Either of the two options below should work:

if %ipa%==4 goto START4;

...

:START4
set /p input=Select a number between 1-2:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
echo %input% is Not Valid!
pause;
if %ipa%==4 goto "START 4";

...

:"START 4"
set /p input=Select a number between 1-2:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
echo %input% is Not Valid!
pause;
 

SoulSparko

Estimable
Jan 29, 2015
2
0
4,520
1
I'm not familiar with the code that you are using, but if it is similar to the languages I do know, maybe try "else if" statements following your "START 2" statement.

It would read as follows:

if %ipa%==2 goto START 2;
else if %ipa%==3 goto START 3;
else if %ipa%==4 goto START 4;
else if %ipa%==5 goto START 5;
else if %ipa%==6 goto START 6;

If that doesn't work, then your question is beyond me.
 

Watchylol

Estimable
Jan 29, 2015
2
0
4,510
0


Else if isn't a batch command. But thanks for the help anyway!
 

JeckeL

Distinguished
Jul 19, 2009
224
1
18,910
41
Because of the space in your goto labels it is just seeing them all as:

if %ipa%==2 goto START
if %ipa%==3 goto START
if %ipa%==4 goto START
So it just goes to the first "START" goto in the code which is the one for the 1-2 choice. If you want to use goto labels with spaces you'll either need to put quotations/apostrophes around them or just not use any spaces

Either of the two options below should work:

if %ipa%==4 goto START4;

...

:START4
set /p input=Select a number between 1-2:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
echo %input% is Not Valid!
pause;
if %ipa%==4 goto "START 4";

...

:"START 4"
set /p input=Select a number between 1-2:
if %input%==1 goto You lost;
if %input%==2 goto PRIZE
echo %input% is Not Valid!
pause;
 

G0ss3yn

Estimable
Jun 18, 2014
6
0
4,510
0


JeckeL is correct, this is also the case in most other programming languages, for example you can't have spaces in the name of a java method such as:

public static void method one() {
}

Compiler will give you some sort of error about a missing parenthesis or semicolon
 
Thread starter Similar threads Forum Replies Date
David___Only Apps General Discussion 0
S Apps General Discussion 4
M Apps General Discussion 3
D Apps General Discussion 2
N Apps General Discussion 1
NoctisLionward Apps General Discussion 2
malavena Apps General Discussion 3
Tom Waller Apps General Discussion 2
P Apps General Discussion 1
S Apps General Discussion 4
A Apps General Discussion 13
Z Apps General Discussion 1
P Apps General Discussion 7
G Apps General Discussion 0
T Apps General Discussion 5
SHADOWSTRIKE1 Apps General Discussion 3
S Apps General Discussion 3
R Apps General Discussion 3
P Apps General Discussion 2
M Apps General Discussion 3

ASK THE COMMUNITY