我编写了这个程序,将分数转换为百分比,但我的goto命令被跳过了。它通过程序并跳过if语句。这是代码:
@echo off
:menu
Echo Fraction to Percent=1
Echo Percent to Fraction =2
set /p choice =Enter the number of your choice:
if choice == 1 goto ftp
if choice == 2 goto ptf
if choice == 3 Exit
:ptf
pause
:ftp
set /p tn= Enter the top number:
set /p bn= Enter the Bottom number:
set /a mtn= %tn% * 100
set /a cf= %mtn% / %bn%
set /a cf2= %cf% * 10000
set /a mtn3= %tn% * 1000000
set /a cf3= %mtn3% / %bn%
set /a cf4= %cf3% - %cf2%
set /a cf5= %cf2% / 10000
echo %cf5%.%cf4%
goto continue
:continue
set /p con =Continue? (y/n):
if con ==y goto ftp
if con ==n goto menu
答案 0 :(得分:1)
在这一行:set /p choice =Enter the number of your choice:
choice
是一个var因此它应该像var那样引用
%choice%
代替choice
,如果我建议做... {
if "%choice%"=="1" goto ftp
尝试在wikipedia (batch file)页面上添加引号示例
if "%choice%"=="1" goto shutdown
另请参阅此处有关if语句的更多信息:http://www.robvanderwoude.com/if.php