locked
How to provide operator has a string RRS feed

  • General discussion

  • I am trying to do scripting using if else statement.output not getting as expected

    @echo off
     
     set /p num1=
     set /p oper=
     set /p num2=
     
     if %oper%=="+" (
    set /a Add=%num1%+%num2%
    echo Addition of two number is %Add%
    pause
    )
    else if %oper%=="-" (
    set /a Sub=%num1%-%num2%
    echo Addition of two number is %Sub%
    pause
    )

    • Changed type Bill_Stewart Friday, July 27, 2018 7:52 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 7:53 PM This is not "teach me basics of cmd.exe batch scripting" forum
    Thursday, May 10, 2018 3:00 PM

All replies

  • Switch to PowerShell instead of using cmd.exe batch scripting.

    -- Bill Stewart [Bill_Stewart]

    Thursday, May 10, 2018 4:33 PM
  • Take the double-quotes away from if %oper%==+ and if %oper%==-.  


    • Edited by JS2010 Saturday, May 12, 2018 3:22 PM
    Saturday, May 12, 2018 3:21 PM