Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

batch file - Trouble with LESS and GREA excetra if commands

I have solved my previous question but after editing, I started adding some lines. This is supposed to ask for the age and all that works for me is EQU and not LESS or GREA; So only "No" works. Everything else= "The syntax of the code is wrong." Thanks for helping previously, though! Possibly even this one. I can not be bothered to add 4 lines to the beginning of all my code BTW so is there any tips to help me do it quicker:

:Next1
echo You know, %name%, I just really cannot differ how old  you are. I would       love to know. Do not hesitate to say "No" if  you would not really like to  tell me, but I would like to know.
set /p age
if /i  "%age%" EQU "No" goto :NoAge
if /i "%age%" LESS 12 goto :Young
if /i "%age%" GREA 12 goto :Older
:Older
if /i "%age%" LESS 18 goto :Teen
goto :Adult
:Young
echo Oh, so you are quite young, are you! Well, that is ok, we can still have a little chat!
set "%age%" Young
:Teen
Oh, a teenager... I AIN'T MESSIN' WIT' YOU!
pause
end
:Adult
echo Ah, a good old adult. Lovely!
set "%age%" Older
goto :Next2
:NoAge
echo Well, that is ok (as I did say!) So, do not worry!
goto :Next2
:Next2
pause
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

here are a few changes, before carrying on with your project you really do need to do some reading.

:Next1
echo You know, %name%, I just really cannot tell how old you are.
echo Do not hesitate to say "No" if you would not really like to tell me,
set /p "age=but I would like to know. "
if /i "%age%" EQU "No" goto :NoAge
if "%age%" LSS "12" goto :Young
if "%age%" GTR "12" goto :Older
goto :Next1
:Older
if "%age%" LSS "18" goto :Teen
goto :Adult
:Young
echo Oh, so you are quite young, are you!
echo Well, that is ok, we can still have a little chat!
set "age=Young"

:Teen
Oh, a teenager... I AIN'T MESSIN' WIT' YOU!
pause
exit
:Adult
echo Ah, a good old adult. Lovely!
set "age=Older"
goto :Next2
:NoAge
echo Well, that is ok (as I did say!) So, do not worry!
goto :Next2
:Next2
if /i "%age%" EQU "Young" goto :Young-next2
goto :Adult-next2
:Young-next2
echo Young %name%, would you like to play a game of rock, paper, scissors? (Y/N)
set /p "RPS=Y/N "
if /i "%RPS%" EQU "Y" goto :Yes
if /i "%RPS%" EQU "N" goto :No
goto :Young-next2

You need to fill in something at the blank line, probably a goto, depending upon how you are going to have a chat. If you don't do that the code will go straight into the :Teen label.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...