Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 为什么CMD会说“为什么”在这个时候是出人意料的”;并在提示中输入内容时关闭?_Windows_Batch File - Fatal编程技术网

Windows 为什么CMD会说“为什么”在这个时候是出人意料的”;并在提示中输入内容时关闭?

Windows 为什么CMD会说“为什么”在这个时候是出人意料的”;并在提示中输入内容时关闭?,windows,batch-file,Windows,Batch File,我最近看了一个VSauce 2的视频,里面有一个你总能赢的游戏,我制作了一个程序,玩家可以和电脑玩这个游戏。问题是,当轮到用户时,当您输入一个数字(或任何内容)时,程序关闭。我和我的一个朋友也试图解决这个问题,但没有任何效果。你能帮忙吗 下面是一段不断出错的代码: :usr cls echo. echo SUM: %tot% echo. echo LAST ENTRY: echo COMPUTER: %com% echo YOU: %usr% echo. echo. set/p usr=ENTE

我最近看了一个VSauce 2的视频,里面有一个你总能赢的游戏,我制作了一个程序,玩家可以和电脑玩这个游戏。问题是,当轮到用户时,当您输入一个数字(或任何内容)时,程序关闭。我和我的一个朋友也试图解决这个问题,但没有任何效果。你能帮忙吗

下面是一段不断出错的代码:

:usr
cls
echo.
echo SUM: %tot%
echo.
echo LAST ENTRY:
echo COMPUTER: %com%
echo YOU: %usr%
echo.
echo.
set/p usr=ENTER A NUMBER BETWEEN 1 AND 10: 
if "%usr%" => "11" (
goto usr
)
if "%usr%" =< "0" (
    goto usr
)
set/a tot=%tot%+%usr%
if "%tot%" == "100" (
    goto win
)
if "%tot%" => "101" (
    goto lose
) else (
    goto com
)
:usr
cls
回声。
回音和:%tot%
回声。
回显最后一项:
回显计算机:%com%
回复您:%usr%
回声。
回声。
set/p usr=输入一个介于1和10之间的数字:
如果“%usr%”=>11(
转到usr
)
如果“%usr%”=<“0”(
转到usr
)
集合/a总计=%tot%+%usr%
如果“%tot%”=100(
后来居上
)
如果“%tot%”=>101(
走投无路
)否则(
转到com
)
每一次转到其他存在的地方

1<代码>usr作为标签和变量的名称 将
usr
用作环境变量的标签和名称不是一个好主意,因为这会使搜索标签或变量
usr
变得困难



2.无效参数
=>
=>
不是一回事。Windows批处理文件是一种更痛苦的编程方式。您确定不想使用更好的语言吗?
Gtr
Lss
eq
GEq
&
LEq
都是进行数字
If
比较时可用的选项。您可能在发布问题之前阅读了帮助文件吗?
set /P "usr=ENTER A NUMBER BETWEEN 1 AND 10: "
@echo off

:GetValue
set "UserValue="
set /P "UserValue=Enter a number between 1 and 10: "

rem Has the user not entered any string?
if not defined UserValue goto GetValue

rem Remove all double quotes from entered string.
set "UserValue=%UserValue:"=%"

rem Is there no string left anymore?
if not defined UserValue goto GetValue

rem Does the string contain any other character than a digit?
for /F delims^=0123456789^ eol^= %%I in ("%UserValue%") do goto GetValue

rem Remove all leading zeros because of an integer with a leading 0
rem is interpreted on IF comparsion below as an octal number and 08
rem and 09 would be interpreted as 0 because of invalid octal numbers.
:RemoveLeadingZeros
if "%UserValue:~0,1%" == "0" (
    set "UserValue=%UserValue:~1%"
    if not defined UserValue goto GetValue
    goto RemoveLeadingZeros
)

rem More than two digits are not allowed for a number in range 1 to 10.
rem This check must be done because of the user could enter also the
rem string 12345678901234567890 which is greater maximum positive 32-bit
rem integer value 2147483647 supported on conversion from string to integer.
if not "%UserValue:~2,1%" == "" goto GetValue

rem A value greater 10 is not allowed as also value 0 detected already
rem on removing leading zeros because of TempValue not defined anymore.
if %UserValue% GTR 10 goto GetValue

echo You entered the value %UserValue%.
pause
@echo off
%SystemRoot%\System32\choice.exe /C 1234567890 /N /M "Enter 1 to 0 (=10): "
set "UserValue=%ERRORLEVEL%"
echo You entered the value %UserValue%.
pause
%SystemRoot%\System32\choice.exe /C 0123456789 /N /M "Enter 0 to 9: "
@echo off
:UserInput
cls
echo/
echo SUM: %tot%
echo/
echo LAST ENTRY:
echo COMPUTER: %com%
echo YOU: %usr%
echo/
echo/
%SystemRoot%\System32\choice.exe /C 0123456789 /N /M "Enter 0 to 9: "
set /A tot+=%ERRORLEVEL%
if %tot% EQU 100 goto win
if %tot% GTR 100 goto lose
echo Reached code for "com".
goto :EOF

:win
echo Reached code for "win".
goto :EOF

:lose
echo Reached code for "lose".