2014-11-14 53 views
-1

我正在构建一个简单的计算器,并且想知道为什么我的if语句不工作。谁能帮忙?如果语句问题批量

代码:

title Addition 
color a 
@echo off 
cls 
:add 
cls 
echo What would you like to do? 
echo [1]Set first number [2]Set second number [3]Add 1 and 2 [4]Quit [5]Main Menu 
set /p act= 
if act==1 then goto :1 
if act==2 then goto :2 
if act==3 then goto :num 
if act==4 then goto :quit 
if act==5 then goto :menu 
:1 
cls 
echo What is your first number? 
set /p 1= 
cls 
goto :add 
:2 
cls 
echo What is your second number? 
set /p 2= 
cls 
goto :add 
:num 
num=1+2 
echo Your number is %num% 
pause 
cls 
goto :add 
:quit 
:menu 
SimpleCalulator.bat 
+2

“不工作”是什么意思? – indiv 2014-11-14 20:52:59

回答

0

为了得到一个变量的值,你需要(使用延迟扩展时或!)与%将其包围。你还需要引用你的变量,除非你真的有充分的理由不这样做。另外,“then”不是批处理文件关键字。

if "%act%"=="1" goto :1 
if "%act%"=="2" goto :2 
if "%act%"=="3" goto :num 
if "%act%"=="4" goto :quit 
if "%act%"=="5" goto :menu 
REM Don't forget to handle unexpected user input: 
goto :add