Its basicly a uses the %random% command to generate a number between 1 and 49 six times,
the user inputs 6 numbers then the batch file compares them and adds the amount of matches to a variable.
i will release the code on the 25th of august.
--=BatMaster=--
p.s. i removed the poll
A Lottery Batch file
Moderator: DosItHelp
A Lottery Batch file
Last edited by BatMaster on 20 Aug 2011 10:45, edited 3 times in total.
Re: A Lottery Batch file
Hi BatMaster,
for some reason polls don't work in this forum. I'm going to ask the forum owner why.
Writing a lottery code is an old exercise but a good exercise for learning comparisons.
Regards
aGerman
for some reason polls don't work in this forum. I'm going to ask the forum owner why.
Writing a lottery code is an old exercise but a good exercise for learning comparisons.
Regards
aGerman
Re: A Lottery Batch file
Thanks for the advice aGerman
Re: A Lottery Batch file
as promised here is the code
Code: Select all
@echo off &setlocal
title TheLottery
set/a wins=0
:Start
cls
echo choose your numbers. 1-10 only!
set/p n1=1st:
set/p n2=2nd:
set/p n3=3rd:
set/p n4=4th:
set/p n5=5th:
set/p n6=6th:
:play1
if not "%n1%"=="%random% %% 10" goto play2
set/a wins="%wins% + 1"
:play2
if not "%n2%"=="%random% %% 10" goto play3
set/a wins="%wins% + 1"
:play3
if not "%n3%"=="%random% %% 10" goto play4
set/a wins="%wins% + 1"
:play4
if not "%n4%"=="%random% %% 10" goto play5
set/a wins="%wins% + 1"
:play5
if not "%n5%"=="%random% %% 10" goto play6
set/a wins="%wins% + 1"
:play6
if not "%n6%"=="%random% %% 10" goto draw
set/a wins="%wins% + 1"
:draw
cls
echo You got %wins% numbers right.
pause
Re: A Lottery Batch file
Nice first shot,
but that's not a lottery program, as it requires also the correct order of the numbers.
So it's a difference if you take 1,2,3 or 3,2,1 as your numbers.
I would prefer "batch-arrays" like
jeb
but that's not a lottery program, as it requires also the correct order of the numbers.
So it's a difference if you take 1,2,3 or 3,2,1 as your numbers.
I would prefer "batch-arrays" like
Code: Select all
rem ** Get the numbers from the player
for /L %%n in (1,1,10) DO(
set /p num[%%n]=%%nst:
)
rem ** The lottery numbers
for /L %%n in (1,1,10) DO(
set /a lottery[%%n]=!random! %% 10
)
rem ** Search for each num[n] if it exists in lottery[] and if so add +1 to a correct counter
... (code is obvious)
jeb