问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/40310920/trouble-with-less-and-grea-excetra-if-commands