home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1992
/
13
/
add.bat
next >
Wrap
DOS Batch File
|
1991-11-22
|
3KB
|
120 lines
%@%echo off
cls
if %1!==! goto instr
echo Calculations are in PROGRESS!
set num1=%1
set num2=%2
strings sign1 = left %1,1
if not %sign1%==- goto cont1
strings num1 = mid %num1%,2,128
:cont1
strings /p~ decpos1 = find ~~%num1%~.
if not %decpos1%==0 goto havdec1
goto gettwo
:havdec1
strings decpos1 = add %decpos1%,1
strings dec1 = mid %num1%,%decpos1%,128
strings decpl1 = length %dec1%
strings decpos1 = sub %decpos1%,2
strings num1 = left %num1%,%decpos1%
set num1=%num1%%dec1%
:gettwo
strings sign2 = left %2,1
if not %sign2%==- goto cont2
strings num2 = mid %num2%,2,128
:cont2
strings /p~ decpos2 = find ~~%num2%~.
if not %decpos2%==0 goto havdec2
goto chkdp1
:havdec2
strings decpos2 = add %decpos2%,1
strings dec2 = mid %num2%,%decpos2%,128
strings decpl2 = length %dec2%
strings decpos2 = sub %decpos2%,2
strings num2 = left %num2%,%decpos2%
set num2=%num2%%dec2%
:chkdp1
strings sub %decpl1%,%decpl2% > nul
if not errorlevel 1 goto chkdp2
strings num1 = mul %num1%,10
strings decpl1 = add %decpl1%,1
goto chkdp1
:chkdp2
strings decpl = sub %decpl1%,%decpl2%
if %decpl%==0 goto addition
strings num2 = mul %num2%,10
strings decpl2 = add %decpl2%,1
goto chkdp2
:addition
if %sign1%==- goto chg1
set sign1=
:chk2
if %sign2%==- goto chg2
set sign2=
goto moreadd
:chg1
set sign1=1
goto chk2
:chg2
set sign2=1
:moreadd
strings sign = add %sign1%,%sign2%
if not %sign%==0 if not %sign%==2 goto subtract
strings answer = add %num1%,%num2%
:getdecprt
strings decprt = right %answer%,%decpl1%
strings len = length %answer%
strings intlen = sub %len%,%decpl1%
strings int = left %answer%,%intlen%
set answer=%int%.%decprt%
if %sign2%!==! set sign2=+
if .%sign2%==.1 set sign2=
if %sign%==2 set mark=-
echo %1%sign2%%2 = %mark%%answer%
goto end
:subtract
strings answer = sub %num1%,%num2% > nul
if errorlevel 1 goto otherway
if .%sign1%==.1 set mark=-
goto getdecprt
:otherway
strings answer = sub %num2%,%num1%
if .%sign2%==.1 set mark=-
goto getdecprt
:instr
echo + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
echo.
echo ALGEBRAIC ADDITION (minus signs accepted)
echo.
echo Enter the numbers you wish to add after %0;
echo.
echo such as: ADD 3.57 5.75
echo ADD -3.57 -5.75
echo ADD 3.57 -5.75
echo ADD -3.57 5.75
echo.
echo (Remember, subtracting negative numbers the sign is changed.)
echo.
echo - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -
:end
set num1=
set dec1=
set decpl1=
set decpos1=
set sign1=
set num2=
set dec2=
set decpl2=
set decpos2=
set sign2=
set sign=
set mark=
set answer=
set decpl=
set decprt=
set len=
set int=
set intlen=
echo.
echo.