Compare two numbers in a batch file

前端 未结 2 803
醉酒成梦
醉酒成梦 2021-01-28 06:04

I searched this site for my question, but I didn\'t find a solution to my problem.

The system gives a random number for the player and for the computer, from 2 to 12.

相关标签:
2条回答
  • 2021-01-28 06:04

    1) You forgot to close your last parenthesis

    2) The syntax error is here :

    if %enemynum% EQU %playernum%
    (
    

    It should be : if %enemynum% EQU %playernum% (

    3) The value of the money variable will be wrong when displayed.

    It's caused by the two facts: -> Inside a FOR or a IF, the variables are "expanded" before and not during command execution. ( expanded = the variable is remplaced by its value )

    In order to change the value of a variable and use it in the same loop, you should use the delayed expression.

    You must write SETLOCAL ENABLEDELAYEDEXPANSION at the beginning of your code and the variable whose expansion should be delayed should be surrounded by exclamation marks instead of percent signs.

    So echo Your current money is %money%. become echo Your current money is !money!.

    4) You must escape your parenthesis in case of tie : echo You won the bet ^(%bet%^) but your money didn't changed.

    5) You didn't put a label INTRO, so your goto INTRO will fail

    0 讨论(0)
  • 2021-01-28 06:10

    you should search for delayed expansion (setlocal enabledelayedexpansion) and count your brackets: every opening bracket needs a closing one (there are exceptions I know, but not here). The opening bracket after if must be on the same line like if. The if parser will stop here: %bet%) because this is the first closing bracket after the last opening.

    0 讨论(0)
提交回复
热议问题