ch4rl1e97

Add.bat

Sep 12th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.85 KB | None | 0 0
  1. @SET %ERRORLEVEL%=0
  2. REM Error checks
  3. @IF "%~1"=="" (ECHO ERROR: No Input^! Try "Add help"&&PAUSE&&EXIT /b 1)
  4.  
  5. @IF /I "%~1"=="help" goto help
  6. @IF "%~1"=="?" goto help
  7.  
  8. @SET /a errorcheck=%~1 >nul 2>&1
  9. @IF NOT %ERRORLEVEL% EQU 0 (ECHO Add only accepts integer number input^! Try "Add Help"&&PAUSE&&EXIT /b 1)
  10. @IF "%~2"=="" (ECHO ERROR: Missing second input^! try "Add help"&&PAUSE&&EXIT /b 1)
  11. @SET /a errorcheck=%~2 >nul 2>&1
  12. @IF NOT %ERRORLEVEL% EQU 0 (ECHO Add only accepts integer number input^! Try "Add Help"&&PAUSE&&EXIT /b 1)
  13.  
  14. REM Actual maths
  15. @SET /a "result=%1+%2"
  16. @ECHO %1 + %2 = %result%
  17. exit /b 0
  18.  
  19. REM Help message
  20. :help
  21. ECHO Addition of two integer numbers
  22. ECHO.
  23. ECHO Example usage:
  24. ECHO Add [Number] [Number]
  25. ECHO Result is stored in ^%result^%
  26. ECHO.
  27. ECHO Add [?/help]
  28. ECHO Display this help message.
  29. ECHO.
  30. PAUSE
  31. EXIT /b 0
Advertisement
Add Comment
Please, Sign In to add comment