@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