206Views2Replies

Author Options:

Can anyone explain why this batch file doesn't work correctly? Answered

this is the code: @echo off

:Side
ping localhost -n 2


:Main
cls
color Fc

echo  Rock, Paper, Scissors!
pause
echo How to play:
pause
echo Type either Rock, Paper or Scissors in the bar and press enter, your opponents
choice will show, and repeat!
pause

:Start
cls
set /p %input0%= Enter your choice here :


:ans
set /a ran=%random%
if /i %ran% GTR 7 goto :1
if /i %ran% LSS 7 goto :2
if /i %ran% LSS 4 goto :3


:1
if %input0%== Scissors
echo Your opponent chose Rock, Rock beats Scissors, you lost!
else
echo You Win!
pause
goto Start
:2
if %input0%== Rock
echo You Win!
else
echo Your opponent chose Paper, Sorry you lose!
pause
goto Start
:3
if %input0%== Paper
echo You Win!
else
echo Your opponent chose Scissors, Sorry you lose!
pause
goto Start

can someone explain why this doesn't work?

Discussions

Another thing to do is move the "LSS 4 " above the "LSS 7". As it stands, you will never go to :3 because any number less than 7, including those less than 4, will go to :2, completely skipping :3.

Qa.

What do you mean "does not work"?

If you get weird errors I suggest to save in a ANSI format, apart from that the LSS and GTR commands are used for numbers, not words.

So you would have to assign a number the choice entered.

You generate a random number between 0 and 32767 to compare with a text input - like comparing apples to bricks ;)

You need another echo in front of choice will show, and repeat! or else it sees choice as a command.

Afterthat it gives a syntax command error, maybe you've left out some subs.

thanks for the help!