有批量变量问题

时间:2016-05-19 01:24:04

标签: algorithm variables batch-file

所以我一直在批处理一个程序,它在用户定义的范围内找到一个整数。它的工作原理是:

  1. 输入范围
  2. 找到中间距离并询问是否需要#更高
  3. 将最高/最低数字设置为范围的参数之一。
  4. 冲洗并重复步骤2-4,直至找到正确的数字。
  5. CODE(WIP)

        title THE AI
    @echo off
    set /a attempts=0
    color a
    cls
    
    :setup
    ::sets up the range. e.g. from 5-600
    set /p mini="Enter minimum number here:"
    echo Succesfully read minimum number, %mini%
    set /p maxi="Enter maximum number here:"
    echo Succesfully read maximum number, %maxi%
    
    :bugfix1
    
    cls
    
    ::Makes sure the maximum number is higher than minimum number
    if %maxi% LEQ %mini% (
    echo Your minimum number is either higher than your maximum, or the same.
    echo Or, you put in a decimal. Shame on you. Please fix it
    echo.
    echo.
    echo Or, in short, YOU'RE STUPID AND CAN'T FIGURE OUT NUMBERS. FIX!!! NOW!!!
    pause
    cls
    goto setup) ELSE (
    echo You are good to go!
    
    ::sets up for finding the difference
    set numbig=%maxi%
    set numsmall=%mini%
    
    echo %numsmall% is the numsmall variable
    echo %numbig% is the numbig variable
    pause
    )
    
    
    :Actual_1
    ::Finds the difference.
    set /a range = %numbig%-%numsmall%
    
    ::finds the half mark in the range and adds minimum number to it to find the true middle.
    set /a newnum1 = (%range%/2)+%mini%
    
    ::sees if the number is higher or lower than given number
    echo Is the desired number higher than %newnum1%? (y/n)
    echo Or, if the correct answer was found, enter ppp.
    set /p booleanfinder = Please enter y or n
    ::Activates if the number is lower than desired number.
    echo %numsmall%
    if /i "%booleanfinder%" == "y" goto TheDesiredNumberIsHigher
    
    ::| set attempts = %attempts%+1 | goto Actual_1  |pause 
    
    if /i "%booleanfinder%" == "n" goto TheDesiredNumberIsLower
    
    ::  if /i %booleanfinder% == ppp (
    ::echo I took %attempts% to get the answer.) ELSE (
    ::  echo Why can't you type? 
    ::  echo Going back to the "Actual_1" function
    ::  echo Try to type better this time.)
    ::pause
    
    :TheDesiredNumberIsHigher
    ::If the desired number is higher than that of %booleanfinder%'s
    set numsmall = %newnum1%
    echo %numsmall% is the lowest number possible
    pause
    goto Actual_1
    
    :TheDesiredNumberIsLower
    
    set numbig = %newnum1%
    echo %newnum1% is now the highest number possible
    pause
    goto Actual_1
    
    :YouGotIt
    

    但大多数情况下,我在本节中遇到了问题

    goto setup) ELSE (
    echo You are good to go!
    
    ::sets up for finding the difference
    set numbig=%maxi%
    set numsmall=%mini%
    
    echo %numsmall% is the numsmall variable
    echo %numbig% is the numbig variable
    pause
    )
    

    看来,当我尝试回显%numbig%或%numsmall%时,它只给我一个空白数字。 (这两个变量已在代码中定义)

    感谢任何帮助。谢谢你的阅读!

0 个答案:

没有答案