如果语句问题批处理

时间:2014-11-14 20:50:41

标签: batch-file if-statement

我正在构建一个简单的计算器,我想知道为什么我的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

1 个答案:

答案 0 :(得分:0)

要获取变量的值,您需要使用%(或使用延迟扩展时为!)将其包围。你还需要引用你的变量,除非你真的有充分的理由不这样做。此外,"然后"不是批处理文件关键字。

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
相关问题