![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-05 22:50 |
48,039 topics / 350,124 posts / today 2 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » Guess the number game [game's over] |
| Printable Version 2,536 / 16 |
| Floor16 26933062 | Posted 2007-09-26 21:03 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
```
@echo off set count=10&set ci=1 :loop set /a ss=%random%%%9+0 for %%n in (%var%) do if "%ss%" == "%%n" goto loop set var=%var% %ss% set /a b+=1 if %b% lss 4 goto loop set var=%var: =% :lis if %count% equ 0 goto tui set wei=0 set dui=0 set num= cls echo.&echo Please enter a 4-digit non-repeating number if %ci% neq 1 ( echo.&echo The results you entered before are&echo. for /f "tokens=2 delims==" %%a in ('set _') do set/p= %%a <nul ) echo. set /p num= if "%num%"=="" goto lis cls if not "%num:~3,1%"=="" (if not "%num:~4,1%"=="" goto weic) else goto weic echo %num%|findstr "^*$">nul||goto csz set "b=%num:~0,1% %num:~1,1% %num:~2,1% %num:~3,1%" set w=0 for %%a in (%b%) do ( for %%i in (%b%) do if %%a==%%i set/a w+=1 set/a w-=1 ) if %w% neq 0 goto cf set/a count-=1 echo.&echo The random number is %var% echo.&echo The number entered by the player is %num% if "%var%"=="%num%" set jie=a4b0&goto ok set "a=%var:~0,1% %var:~1,1% %var:~2,1% %var:~3,1%" set "b=%num:~0,1% %num:~1,1% %num:~2,1% %num:~3,1%" for %%a in (%a%) do ( for %%b in (%b%) do ( if "%%a"=="%%b" set/a dui+=1 )) if "%var:~0,1%"=="%num:~0,1%" set/a wei+=1 if "%var:~1,1%"=="%num:~1,1%" set/a wei+=1 if "%var:~2,1%"=="%num:~2,1%" set/a wei+=1 if "%var:~3,1%"=="%num:~3,1%" set/a wei+=1 set/a dui=dui-wei if "%dui%" lss "0" set dui=0 set _jie%ci%=%num% A%wei%B%dui% echo.&echo The result you guessed is A%wei%B%dui% echo.&echo You have %count% chances left You have entered %ci% times set/a ci+=1 echo.&pause goto lis :ok color f9 echo.&echo You entered %ci% times Guessed right %jie% echo.&pause exit :weic echo.&echo The number of digits you entered is incorrect, it should be 4 digits. echo.&pause goto lis :csz echo.&echo The number you entered is not a pure number echo.&pause goto lis :cf echo.&echo The number you entered has duplicate digits echo.&pause goto lis :tui cls&echo You guessed wrong 10 times pause ``` |
|
| Floor17 dosmania | Posted 2007-09-26 21:05 |
| 初级用户 Posts 54 Credits 172 | |
|
to s11ss:
I just asked whether each of the four random digits repeats or not. Now I understand. Don't say too much. |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |