@echo off
if "%1"=="" (
:WriteAgain
set x=
set /p variables=Write your expression
if "%variables%"=="help" (
echo Use arithmetical operations and numbers without spaces. + for sum, * for multiplication,/for
devision, - for subtraction
exit
) else (
set variables=%variables: =%
set /a x=%Variables% 2>Error.txt
if %errorlevel% neq 0 goto ErrorOccured
echo %x%
pause
exit
)
:ErrorOccured
echo Your expression is not valid
goto WriteAgain
) else (
set variables=%*
set variables=%variables: =%
set /a x=%variables% 2>Error.txt
if %errorlevel% neq 0 goto ErrorOccured
echo %x%
)
问候,这是一个简单的计算。它可以直接从CMD中使用,但第一if
不工作,也无法通过如果在.bat文件中
) else (
set variables=%variables: =%
set /a x=%Variables% 2>Error.txt
if %errorlevel% neq 0 goto ErrorOccured
echo %x%
总是ErrorOccured
。我没有看到任何问题,它没有第一个工作if
'批处理中不支持if-else-else'。另外跳入内部或进入''(''block')'也是一个坏主意。每个'goto'都会打破块的上下文。重新思考你的逻辑(程序流程)。 – Stephan
另外,标签在()内不受支持。第一个回声格式错误 – Paul