Maximum.bat

Solved
Nangel38 Posted messages 2 Status Member -  
Nangel38 Posted messages 2 Status Member -
Hello,
I’m starting in informatique and can’t figure out how to write the maximum.bat command that calculates in the environment variable MAX and displays the maximum of a list of integers passed as parameters
I created my MAX variable in my batch directory but I can’t write my script
thanks in advance

here is what I’ve already written :
@echo off
if "%1"=="/?" goto usage
if "%1"=="" ( echo No parameters: enter at least 1 integer
goto fin )
rem there is at least one integer
set MAX= %1
shift
:tantque
if "%1"=="" goto fintantque
set /a "diff=MAX-%1"
if "diff"=="-" ( set MAX= %1 )
shift
goto tantque
:fintantque
echo the maximum value is : %MAX%
goto fin
:usage
echo command format : Maximum nb1 nb2 ... nbn
:fin
Configuration: Windows Vista Firefox 3.5.3

1 answer

  1. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 660
     
    hello
    try like this
    C:> bb 10 3 4 5 the maximum value is: 10 C:> bb 10 3 4 5 999 the maximum value is: 999 C:> type bb.bat @echo off if "%1"=="?/" goto usage if "%1"=="" ( echo No parameter: enter at least 1 integer goto fin ) rem at least one integer exists set MAX= %1 shift :while if "%1"=="" goto fintantque set /a diff=MAX-%1 if %diff% LSS 0 set MAX= %1 shift goto tantque :fintantque echo the maximum value is: %MAX% goto fin :usage echo command format: Maximum nb1 nb2 ... nbn :fin 
    0
    1. Nangel38 Posted messages 2 Status Member
       
      Thank you very much, it's magical, it works ;)
      0