Problem with batch comparisons

0

Good afternoon. I was doing a simple batch file, in general, a friend of mine needed me to make that riddle of the 3 gallons of batch water. In general, the batch logic is very simple, however it has a problem in the comparison, where there is the line:

set /A VARIAVELVASO3NO1=%CONTEUDOVASO3%-%QUANTIDADELIVREVASO1%+10
if "%VARIAVELVASO3NO1%" GEQ "10" (
    set/a CONTEUDOVASO3=%CONTEUDOVASO3%-%QUANTIDADELIVREVASO1%
    set/a CONTEUDOVASO1=8
    goto JOGOVASOS
) ELSE (
    set/a CONTEUDOVASO1=%CONTEUDOVASO3%+%CONTEUDOVASO1%
    set/a CONTEUDOVASO3=0
    goto JOGOVASOS
)

The value that% VARIAVELVASO3NO1% stays is 8, since% CONTEUDOVASO3% is equal to 3; and% QUANTITYELIVREVASO1% is equal to 5 (3-5 + 10 = 8). However, instead of entering the FALSE state (which would be ELSE) it enters the first, which is the TRUE state, I first thought it was a problem with negative numbers, so I put everything above 10 (so the +10 in formula) but still the problem persists, any idea what it might be?

    
asked by anonymous 30.04.2018 / 21:31

2 answers

1

Remove quotation marks:

if %VARIAVELVASO3NO1% GEQ 10 (
    set/a CONTEUDOVASO3=%CONTEUDOVASO3%-%QUANTIDADELIVREVASO1%
    set/a CONTEUDOVASO1=8
    goto JOGOVASOS
)
    
30.04.2018 / 22:11
1
  

Darius of the coast, I always recommend making comparisons without quotes

     

Make comparisons only with quotation marks when comparing strings with   several words.

     

and do it as follows:

    if "%string1%" equ "%string2" (Echo.São iguais) Else (
    Echo.Não são iguais
    )
  

That's the tip.

    
01.05.2018 / 02:20