Thanks
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
This is a *.bat file I wrote by copying the example in a book, but it gives an error when run.
Please help me take a look
@echo off
choice /c:mde mem,defrag,end
if errorlevel 3 goto mem(you should test the highest error code value first)
if errorlevel 2 goto defrag
if errotlevel 1 goto end
:mem
mem
goto end
:defrag
c:\windows\defrag.exe
goto end
:end
echo good bye
The following is quoted from iceboy's post on 2003-10-6 15:42:54:
Yes! The simplest method is to use Choice.com; if you want something more complicated, use Menustar or ChoiceX, or just write a small program too.
OS:: Solve.bat - program for verifying Goldbach's conjecture
:: Will Sort - 2004/11/18
::
:: Modified from a prime-number piling program
:: Environment variable notes:
:: iTest: test number, iPrime: prime number index
:: divisor: divisor used to test primes, iDivisor: divisor index
:: Factor1&Factor2: the two factors of the even number, iFactor1&iFicator2: factor indices
:: less: marker for not enough to divide in division, diff: marker for a difference value in subtraction
::
@echo off
if == goto %2
if == %comspec% /e:4096 /c %0 $ init
del ~Solve.bat
goto end
:: Initialization: generate prime 2, store it as the first prime, set the loop starting value to 3
:init
set iTest=I I
set iPrime=I
set %iPrime%=I I
:: For odd numbers %iTest% from 3~n, divide them by all generated primes from small to large in a loop
:: If none divide evenly then store %iTest% as prime %iPrime%, otherwise jump to Solve
:: Decompose each even number %iTest% from 3~n into the sum of two generated primes
:: If decomposed exactly then display this even number and the two factors, otherwise continue looping MainLoop
:MainLoop
rime - test whether an odd number is prime
set iTest=I %iTest%
set iDivisor=I
rimeLoop
echo set divisor=%%%iDivisor%%%>~Solve.bat
call ~Solve.bat
call %0 $ Divide %iTest%
if "%less%"=="" goto Solve
if "%iDivisor%"=="%iPrime%" goto IsPrime
set iDivisor=I%iDivisor%
goto PrimeLoop
:IsPrime
set iPrime=I%iPrime%
set %iPrime%=%iTest%
:Solve - decompose an even number into the sum of primes
set iTest=I %iTest%
set iFactor1=
:SolveLoop
set iFactor1=I%iFactor1%
if "%iFactor1%"=="I%iPrime%" goto SolveLoop
set iFactor2=%iFactor1%
:SolveSubLoop
if "%iFactor2%"=="I%iPrime%" goto SolveLoop
echo set Factor1=%%%iFactor1%%%> ~Solve.bat
echo set Factor2=%%%iFactor2%%%>>~Solve.bat
call ~Solve.bat
call %0 $ Minus %iTest%
if "%diff%"=="" goto IsSolve
set iFactor2=I%iFactor2%
goto SolveSubLoop
:IsSolve
echo %iTest%
echo %Factor1% + %Factor2%
if "%iPrime%"=="IIIIIIIII" goto end
goto MainLoop
:: Divide the passed dividend %iTest% by the divisor %divisor% (repeated subtraction)
:: If it is not enough to divide (cannot divide evenly) then return the not-enough signal less, otherwise return directly
ivide
for %%n in (%divisor%) do shift
if not == goto Divide
set less=
if == set less=true
goto end
:: Subtract the subtrahends %Factor1% and %Factor2% from the passed minuend %iTest%
:: If there is a difference left (cannot be decomposed) then return the difference signal diff, otherwise return directly
:Minus
for %%n in (%Factor1%) do shift
for %%n in (%Factor2%) do shift
set diff=
if "%2"=="" set diff=true
if not "%3"=="" set diff=true
goto end
:end