mardi 15 janvier 2019

Using nested if in Windows Batch. Returning "50 was unexpected at this time"

This code works if I give it any input. If I do not, the first if statement does not echo Mistake. The program is supposed to determine, using an integer argument, whether a grade is passing (>=50) or failing (<50) while making sure the supplied argument is valid (integer between 0 and 100)

@echo off
if "%1%"=="" (
    echo Mistake
) else (
        if %1% geq 50 (
        if %1% gtr 100 (
            call :functionMistake
        ) else (
            call :functionPass
        ) 
    ) else (
        if %1% lss 0 (
            call :functionMistake
        ) else (
            call :functionFail
        )
    )
)
exit /B O
rem The pass function
:functionPass
echo Passed
exit /B O
rem The failed function
:functionFail
echo Failed
exit /B O
rem The mistake function
:functionMistake
echo Please input a number between 0 and 100
exit /B O

Aucun commentaire:

Enregistrer un commentaire