Need help with syntax
Posted: 14 Nov 2009 10:01
I am new at batch file programming (very new), and I tried to make a batch file that would give the factorial of a number between 1 and 10
After fixing any issues with the first line of text, I tried it again and it looped the message "The syntax is incorrect".
For those who don't know, the factorial of a number "x" is 1*2*3*4*...*x
E.g. 4 factorial is 1*2*3*4=24
here is the code, I know there probably are hundreds of mistakes.
After fixing any issues with the first line of text, I tried it again and it looped the message "The syntax is incorrect".
For those who don't know, the factorial of a number "x" is 1*2*3*4*...*x
E.g. 4 factorial is 1*2*3*4=24
here is the code, I know there probably are hundreds of mistakes.
Code: Select all
@echo off
if ("%1" GTR "10") (goto :bad) else (goto :good)
:bad
echo The number is too big
:good
set %n%=1
goto :math
:math
set %m%=%n%+1
if /i not (%m% GTR %1) (goto :matha) else (goto :end)
:matha
set %r%=%b%*%m%
set %b%=%r%
set %n%=%m%
goto :math
:end
echo %1 factorial is %r.
pause
@echo on
cls