你可以嘗試這樣的事情:
@echo off
Title Division Computation
:START
cls
Color 0A
set /p "FN=Enter first number : "
if "%FN%" EQU "22" Exit
::*******************************
:SECONDNUMBER
Color 0A
set /p "SN=Enter second number : "
if "%SN%" EQU "22" Exit
if "%SN%" EQU "0" GOTO ZEROERROR
GOTO DIVIDE
::*******************************
:DIVIDE
set /a RESULT=%FN%/%SN%
echo %FN% divided by %SN% = %RESULT%
pause
cls
GOTO START
::*******************************
:ZEROERROR
Color 0C
echo Sorry! You CAN NOT divide by ZERO. Please enter a new number.
pause
cls
GOTO SECONDNUMBER
::*******************************
這是一個獎金計算器用打字機和我說話的聲音你只是爲了好玩:)
@echo off
Title Calculator with a TypeWriter and Speaking Voice by Hackoo 2016
Color 0A & Mode con cols=80 lines=3
Call :TypeWriter "Hello, Welcome to my calculator. First off would you like to tell me your name ? "
echo(
Call :TypeWriter "So, Whats your name ? "
set /p name=
Call :TypeWriter "Ah, Nice to meet you %name% !"
::*************************************************************
:start
Call :TypeWriter "What is the first number you want to use ? "
set /p no=
Call :TypeWriter "What Operation do you want to use ? "
set /p op=
Call :TypeWriter "What is the second number you would like to use ? "
set /p no2=
Call :TypeWriter "%no% %op% %no2% "
set /a ans=%no% %op% %no2%
Call :TypeWriter " Well, That was an easy one the answer is %no% %op% %no2% = %ans% "
Call :TypeWriter " Would you like to do another calculaton ? Y(Yes) or N(No) ?"
set /p Question=
If /I "%Question%"=="Y" (goto :start) else (Goto :end)
::*************************************************************
:TypeWriter
Cls
echo(
(
echo strText=wscript.arguments(0^)
echo intTextLen = Len(strText^)
echo intPause = 150
echo For x = 1 to intTextLen
echo strTempText = Mid(strText,x,1^)
echo WScript.StdOut.Write strTempText
echo WScript.Sleep intPause
echo Next
echo Set Voice=CreateObject("SAPI.SpVoice"^)
echo voice.speak strText
)>%tmp%\%~n0.vbs
@cscript.EXE /noLogo "%tmp%\%~n0.vbs" "%~1"
exit /b
::**************************************************************
:end
Exit
::*************************************************************
'set/p SN = ...'設置一個名爲'SN' + _space_的變量。 '如果「%SN%」== 22「將帶引號的字符串與未加引號的字符串進行比較,並且因此總是失敗(引號是比較的一部分)。爲了解決這個問題,引用正確的部分('「22」');引用的語法對空字符串是強健的,但沒有引用的語法不是。 – aschipfl
我想我們本週每天都會回答這個問題。與延遲擴展相同。可能是人們無法理解的批處理文件中最常見的兩個錯誤。 – Squashman