Compare two numbers in a batch file

前端 未结 2 801
醉酒成梦
醉酒成梦 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

提交回复
热议问题