Hi! I was able to create this Grade System batch code here. But I need to restrict letters from it.
***************************************************************************************************************
ECHO OFF
CLS
:MENU
ECHO .
ECHO ...............................................
ECHO Type your grade. Press x to exit
ECHO ...............................................
ECHO .
SET M=
SET /P M= Your grade:
IF %M% GEQ 91 IF %M% LEQ 100 goto :E
IF %M% GEQ 81 IF %M% LEQ 90 goto :V
IF %M% GEQ 71 IF %M% LEQ 80 goto :S
IF %M% GEQ 61 IF %M% LEQ 70 goto :VG
IF %M% GEQ 51 IF %M% LEQ 60 goto :G
IF %M% LEQ 50 goto :F
IF %M% EQU x exit
:E
echo Excellent
pause
cls
goto :MENU
:V
echo Very Satisfactory
pause
cls
goto :MENU
:S
echo Satisfactory
pause
cls
goto :MENU
:VG
echo Very Good
pause
cls
goto :MENU
:G
echo Good
pause
cls
goto :MENU
:F
echo FAILED
pause
cls
goto :MENU
***************************************************************************************************************
The flow when inputting numbers is good. But whenever I put letters, it should print "invalid input". Do you have any tips for me? IDK anymore what to do with this. BTW, this is my fist time in coding. I hope to hear from anyone. Thank you ^^.
The first picture is the problem. The 2nd picture is the normal output.
How to restrict 'Letters'
Moderator: DosItHelp
-
- Posts: 1
- Joined: 01 Oct 2017 04:22
How to restrict 'Letters'
- Attachments
-
- This is the problem.
- 2222.png (62.12 KiB) Viewed 2634 times
-
- This is the normal output.
- 111111.png (88.2 KiB) Viewed 2634 times
Re: How to restrict 'Letters'
viewtopic.php?f=3&t=8153#p54167
All you have to do is to explain the teacher how it works.
Steffen
Code: Select all
@echo off &setlocal EnableDelayedExpansion
for %%i in ("9=Excellent" "8=Very Satisfactory" "7=Satisfactory" "6=Very Good" "5=Good") do set "grd%%~i"
:inputloop
set "grd="
set /p "grd=Type your grade. Press x to exit: "
if /i "!grd!"=="x" exit /b
call :check grd 0 100 || goto inputloop
set /a "tenth=(grd-1)/10"
if not defined grd%tenth% (echo Failed) else echo !grd%tenth%!
pause
cls
goto inputloop
:check VarName Min Max
setlocal EnableDelayedExpansion
for /f "delims=1234567890 eol=" %%i in ("!%~1!") do (endlocal &exit /b 1)
2>nul set /a "dummy=!%~1!" || (endlocal &exit /b 1)
if "!%~1!" neq "%dummy%" (endlocal &exit /b 1)
if %dummy% lss %~2 (endlocal &exit /b 1)
if %dummy% gtr %~3 (endlocal &exit /b 1)
endlocal &exit /b 0
All you have to do is to explain the teacher how it works.
Steffen
Re: How to restrict 'Letters'
aGerman wrote: .....
All you have to do is to explain the teacher how it works.
Steffen
Perhaps is simpler this way:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
for %%i in ("9=Excellent" "8=Very Satisfactory" "7=Satisfactory" "6=Very Good" "5=Good") do set "grd%%~i"
for /L %%i in (0,1,4) do set "grd%%i=FAILED"
:Menu
set "M=x"
set /P "M=Type your grade. Press x to exit: "
if /I "%M%" equ "x" goto :EOF
set /A "M=(100%M%%%1000-1)/10" 2>NUL || (echo Invalid input & goto Menu)
if not defined grd%M% goto Menu
echo !grd%M%!
pause
cls
goto Menu
Antonio