Advertisement
Sufferrrrrr

calculator

Mar 8th, 2024
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.09 KB | None | 0 0
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3.  
  4. :calculator
  5. cls
  6. echo Simple Batch Calculator
  7. echo ----------------------
  8. echo 1. Addition
  9. echo 2. Subtraction
  10. echo 3. Multiplication
  11. echo 4. Division
  12. echo 5. Exit
  13.  
  14. set /p choice=Enter your choice (1-5):
  15.  
  16. if "%choice%"=="1" goto addition
  17. if "%choice%"=="2" goto subtraction
  18. if "%choice%"=="3" goto multiplication
  19. if "%choice%"=="4" goto division
  20. if "%choice%"=="5" goto :eof
  21.  
  22. :input
  23. set /p num1=Enter first number:
  24. set /p num2=Enter second number:
  25.  
  26. :math
  27. if "%operation%"=="add" set /a result=num1+num2
  28. if "%operation%"=="sub" set /a result=num1-num2
  29. if "%operation%"=="mul" set /a result=num1*num2
  30. if "%operation%"=="div" (
  31.     if "%num2%"=="0" (
  32.         echo Error: Cannot divide by zero.
  33.         pause
  34.         goto calculator
  35.     ) else (
  36.         set /a result=num1/num2
  37.     )
  38. )
  39.  
  40. :output
  41. echo Result: %result%
  42. pause
  43. goto calculator
  44.  
  45. :addition
  46. set "operation=add"
  47. goto input
  48.  
  49. :subtraction
  50. set "operation=sub"
  51. goto input
  52.  
  53. :multiplication
  54. set "operation=mul"
  55. goto input
  56.  
  57. :division
  58. set "operation=div"
  59. goto input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement