设置/ a不能正常工作2/2

时间:2016-03-07 18:22:04

标签: batch-file

我无法获得%difference_two%工作它可以找到%difference_one%为2但是当我将它除2时它不会显示为任何东西。 使用数字2,5,10,17,26 为了得到我需要的东西。

0022

1 个答案:

答案 0 :(得分:0)

试试这个:

@echo off
setlocal EnableDelayedExpansion
color 0a
title Solver

:numbers
cls
set /p first=First: 
set /p second=Second: 
set /p third=Third: 
set /p fourth=Fourth: 
set /p fifth=Fifth: 
goto solve

:solve
cls
set /a second_minus_first= %second% - %first%
set /a third_minus_second= %third% - %second%
if %third_minus_second%==%second_minus_first% (
goto s
) else (
goto d
)

:d
cls
set /a fourth_minus_third= %fourth% - %third%
set /a difference= %third_minus_second% - %second_minus_first%
set /a difference_one= %fourth_minus_third% - %third_minus_second%
if %difference%==%difference_one% (
set /a difference_two= !difference_one! / 2
set /a thing= !first! - !difference_two!
cls
echo !difference_two!n Squared + !thing!
pause >nul
goto numbers
) else (
goto wrong
)

在批处理中,代码块中的命令(( )之间)被解释为在同一行,因此您需要使用setlocal EnableDelayedExpansion并使用!而不是%在他们里面。