我在结束时试图弄清楚我的批处理文件有什么问题
我似乎无法使某些语句起作用,并且最终的echo语句不会附加到文档中。有人可以加入吗?
如果用户输入66
,我希望第一个num终止如果用户输入零
,我还希望第二个数字跳转到ZeroError我无法弄清楚为什么它不会在最后显示平均值或创建one.txt文件
@echo off
setlocal ENABLEDELAYEDEXPANSION
type NUL > results.txt
:MAIN
echo My Name is ****** > results.txt
echo The Current date is %date% >> results.txt
echo The Current time is %time% >> results.txt
echo My name is ****, the current date is %date% and the current time is %time%
:FirstNum
SET /P FirstNumber=Enter the First Number and press Enter :
if %FirstNumber% == "66" goto LOOP
:SecondNum
SET /P LastNumber=Enter the Second Number and press Enter:
if %LastNumber% == "0" goto ZeroError
if %LastNumber% == "66" goto LOOP
goto CALC
:ZeroError
SET /P zError =You CAN NOT divide by Zero, enter a correct number and press Enter:
if %LastNumber% == "66" goto LOOP
if %LastNumber% == "0" goto ZeroError
goto CALC
:CALC
set /A calculation = %FirstNumber% / %LastNumber%
echo %FirstNumber% divided by %LastNumber% equals %calculation%
echo %FirstNumber% divided by %LastNumber% equals %calculation% >> results.txt
pause
:LOOP
FOR /L %%A IN (1,1,10) DO(
SET /A MOD= %%A %% 6
SET /A MODPlus= !MOD! + 2
SET /A TOTAL += !MODPlus!
SET /A AVERAGE = !TOTAL!/10
)
echo The mean of the values is %AVERAGE% >> results.txt
mkdir pgm4
cd pgm4
type NUL > one.txt
echo REM ***** >> one.txt
echo echo ****** >> one.txt
ECHO. >> one.txt
在我的FirstNum标签中,尽管我在提示符中输入了66,但程序仍在继续
SecondNum中的类似问题
之后的回显:LOOP不会将平均值附加到文本文件中。
有人能指出我做错的方向吗?
答案 0 :(得分:0)
你似乎需要用勺子喂叹息,
"66"
并且只有命令if %FirstNumber% == "66" goto LOOP
可以评估为真,则双方需要相等set /a
计算可以合并为一行,对于变量不需要%
或!
(除了变量)。echo off
setlocal ENABLEDELAYEDEXPANSION
:MAIN
( echo My Name is ******
echo The Current date is %date%
echo The Current time is %time%
) >result.txt
echo My name is ****, the current date is %date% and the current time is %time%
:FirstNum
SET /P FirstNumber=Enter the First Number and press Enter :
if "%FirstNumber%"=="66" goto LOOP
:SecondNum
SET /P LastNumber=Enter the Second Number and press Enter:
if "%LastNumber%"=="0" goto ZeroError
if "%LastNumber%"=="66" goto LOOP
goto CALC
:ZeroError
SET /P zError =You CAN NOT divide by Zero, enter a correct number and press Enter:
if "%LastNumber%"=="66" goto LOOP
if "%LastNumber%"=="0" goto ZeroError
goto CALC
:CALC
set /A calculation=FirstNumber/LastNumber
echo %FirstNumber% divided by %LastNumber% equals %calculation%
echo %FirstNumber% divided by %LastNumber% equals %calculation% >> results.txt
pause
:LOOP
FOR /L %%A IN (1,1,10) DO (
SET /A "MOD= %%A %% 6, MODPlus=MOD + 2, TOTAL+=MODPlus, AVERAGE=TOTAL/10"
)
echo The mean of the values is %AVERAGE% >> results.txt
mkdir pgm4
cd pgm4
( echo REM *****
echo echo ******
echo.
) > one.txt