Question Need help with batch files

Discussion in 'General Discussion' started by Jake9039, Sep 24, 2018.

  1. Jake9039

    Jake9039 Pangalactic Porcupine

    I'm trying to make a rudimentary batch calculator so that I can expand my knowledge on batch files. I can get it to add,subtract,multiply, or devide numerical values if they are defined at the start, but I cannot for the life of me find out howto get it to work whenthe numbers are not already predefined.
    if somebody could help me out, that would be great. I am posting the code here to see if anybody can figure it out.

    @Echo off
    rem "variable settings"
    set /a answer = 0
    set /a num1 = 0
    set /a num2 = 0
    set /a opperator =0
    rem "attempting to get the variables to ask"
    set /p /a num1 = "num1:"
    set /p /a num2 = "num2:"
    choice /c asdm /m "a=+ s=- d=/ m=*"
    set opperator= %errorlevel%
    rem "doing any calculations
    if %opperator%==1 set answer = %num1%+%num2%
    if %opperator%==2 set answer = %num1%-%num2%
    if %opperator%==3 set answer = %num1%/%num2%
    if %opperator%==4 set answer = %num1%*%num2%
    echo %errorlevel%
    echo %answer%
    rem "giving the answer and checking if it worked"
    set num1 = 0
    set num2 = 0
    set answer = 0
    goto start
    rem "repeating the commands"
    Last edited: Sep 24, 2018

Share This Page