home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 13 / add.bat next >
DOS Batch File  |  1991-11-22  |  3KB  |  120 lines

  1. %@%echo off
  2. cls
  3. if %1!==! goto instr
  4. echo Calculations are in PROGRESS!
  5. set num1=%1
  6. set num2=%2
  7. strings sign1 = left %1,1
  8. if  not %sign1%==- goto cont1
  9. strings num1 = mid %num1%,2,128
  10. :cont1
  11. strings /p~ decpos1 = find ~~%num1%~.
  12. if not %decpos1%==0 goto havdec1
  13. goto gettwo
  14. :havdec1
  15. strings decpos1 = add %decpos1%,1
  16. strings dec1 = mid %num1%,%decpos1%,128
  17. strings decpl1 = length %dec1%
  18. strings decpos1 = sub %decpos1%,2
  19. strings num1 = left %num1%,%decpos1%
  20. set num1=%num1%%dec1%
  21. :gettwo
  22. strings sign2 = left %2,1
  23. if not %sign2%==- goto cont2
  24. strings num2 = mid %num2%,2,128
  25. :cont2
  26. strings /p~ decpos2 = find ~~%num2%~.
  27. if not %decpos2%==0 goto havdec2
  28. goto chkdp1
  29. :havdec2
  30. strings decpos2 = add %decpos2%,1
  31. strings dec2 = mid %num2%,%decpos2%,128
  32. strings decpl2 = length %dec2%
  33. strings decpos2 = sub %decpos2%,2
  34. strings num2 = left %num2%,%decpos2%
  35. set num2=%num2%%dec2%
  36. :chkdp1
  37. strings sub %decpl1%,%decpl2% > nul
  38. if not errorlevel 1 goto chkdp2
  39. strings num1 = mul %num1%,10
  40. strings decpl1 = add %decpl1%,1
  41. goto chkdp1
  42. :chkdp2
  43. strings decpl = sub %decpl1%,%decpl2%
  44. if %decpl%==0 goto addition
  45. strings num2 = mul %num2%,10
  46. strings decpl2 = add %decpl2%,1
  47. goto chkdp2
  48. :addition
  49. if %sign1%==- goto chg1
  50. set sign1=
  51. :chk2
  52. if %sign2%==- goto chg2
  53. set sign2=
  54. goto moreadd
  55. :chg1
  56. set sign1=1
  57. goto chk2
  58. :chg2
  59. set sign2=1
  60. :moreadd
  61. strings sign = add %sign1%,%sign2%
  62. if not %sign%==0 if not %sign%==2 goto subtract
  63. strings answer = add %num1%,%num2%
  64. :getdecprt
  65. strings decprt = right %answer%,%decpl1%
  66. strings len = length %answer%
  67. strings intlen = sub %len%,%decpl1%
  68. strings int = left %answer%,%intlen%
  69. set answer=%int%.%decprt%
  70. if %sign2%!==! set sign2=+
  71. if .%sign2%==.1 set sign2=
  72. if %sign%==2 set mark=-
  73. echo %1%sign2%%2 = %mark%%answer%
  74. goto end
  75. :subtract
  76. strings answer = sub %num1%,%num2% > nul
  77. if errorlevel 1 goto otherway
  78. if .%sign1%==.1 set mark=-
  79. goto getdecprt
  80. :otherway
  81. strings answer = sub %num2%,%num1%
  82. if .%sign2%==.1 set mark=-
  83. goto getdecprt
  84. :instr
  85. echo + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
  86. echo.
  87. echo       ALGEBRAIC   ADDITION  (minus signs accepted)
  88. echo.
  89. echo             Enter the numbers you wish to add after %0;
  90. echo.
  91. echo                      such as: ADD  3.57  5.75
  92. echo                               ADD -3.57 -5.75
  93. echo                               ADD  3.57 -5.75
  94. echo                               ADD -3.57  5.75
  95. echo.
  96. echo    (Remember, subtracting negative numbers the sign is changed.)
  97. echo.
  98. echo  - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - 
  99. :end
  100. set num1=
  101. set dec1=
  102. set decpl1=
  103. set decpos1=
  104. set sign1=
  105. set num2=
  106. set dec2=
  107. set decpl2=
  108. set decpos2=
  109. set sign2=
  110. set sign=
  111. set mark=
  112. set answer=
  113. set decpl=
  114. set decprt=
  115. set len=
  116. set int=
  117. set intlen=
  118. echo.
  119. echo.
  120.