Lottery Validation

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 8
Reputation: smorton123 is an unknown quantity at this point 
Solved Threads: 0
smorton123 smorton123 is offline Offline
Newbie Poster

Lottery Validation

 
0
  #1
Jan 4th, 2009
I'm almost finished my lottery program but having trouble with the validation. In the program the user enters their own numbers, these numbers are then stored in the array user. I want the program to validate these numbers to ensure each number is between 0 and 49. I have tried many methods bu none had the correct response. Any help would be much appreciated.
  1. {Note - Validation should occur in the procedure 'get user numbers' . I have removed any attempts so its easier to see}
  2.  
  3. program test;
  4. uses
  5. EmptyPlaceHolderUnit;
  6.  
  7. type
  8. a = array[1..7] of integer; {Starts an array that will store the random numbers created by the lottery}
  9. b = array[1..7] of integer; {Starts an array that will store the users seven lottery numbers}
  10.  
  11. var
  12. i : integer;
  13. k, j, tmp: integer;
  14. numbers: a;
  15. user: b;
  16. counter: integer;
  17.  
  18. var
  19. subscript: integer;
  20. q: integer;
  21.  
  22. procedure initialise (var counter: integer);
  23. begin
  24. counter := 0; {Starts Counter}
  25. end;
  26.  
  27. procedure get_user_numbers (var user: b);
  28.  
  29. begin
  30. writeln ;
  31. writeln( ' You are now playing the Lottery Game ' );
  32. writeln ;
  33. write('Could You Please Select Your Seven Lottery Numbers Between the Range 0 - 49 ');
  34. writeln;
  35. for subscript := 1 to 7 do
  36. begin {Gets user to enter their selected lottery Numbers}
  37. readln(user[subscript]); {Stores User Numbers in the array 'user'}
  38. end;
  39. end;
  40.  
  41. procedure start_game (i:integer; var numbers: a; k ,j, tmp: integer);
  42.  
  43. var
  44. q: integer;
  45.  
  46. begin
  47. writeln;
  48. writeln (' ,---'); {Starting Game Graphic}
  49. writeln (' ( -_-('); {Due to limitations of the interface in Pascal}
  50. writeln (' ) .__/ )'); {I used ASCII art to create a graphic relevant to the game}
  51. writeln (' _/ _/_( / _.---._');
  52. writeln (' (__/ _ _) ,-._ / o \');
  53. writeln (' //)__(\/,-` |_| O o o O|');
  54. writeln ('_\\///==o=\'' | O o o O |');
  55. writeln (' `-''\ / \O o o /');
  56. writeln (' )___\ `''-.-\\');
  57. writeln (' / ,\ \ ____)_(____');
  58. writeln (' / / \ \ ''--..---,,-- ');
  59. writeln (' /() >() \\_//');
  60. writeln (' |\_\ |\_\ /,-.\');
  61.  
  62.  
  63. writeln ;
  64. writeln (' And tonights Lottery Balls are...');
  65. writeln ;
  66.  
  67.  
  68. begin
  69. randomize;
  70. for q := 1 to 7 do
  71. begin
  72. numbers[q] := (random(50)); {Selects and displays 7 random integers from the range 0 - 49}
  73. write(numbers[q],' ');
  74. end;
  75. end;
  76. end;
  77.  
  78. procedure sort_nums ( numbers: a; k, j, tmp: integer);
  79. var
  80. q: integer;
  81.  
  82. begin
  83.  
  84.  
  85.  
  86. for k := 1 to 6 do
  87. for j := k + 1 to 7 do
  88. if numbers[k] > numbers[j] then {Sorts numbers into ascending order}
  89. begin
  90. tmp := numbers[k];
  91. numbers[k] := numbers[j];
  92. numbers[j] := tmp;
  93. end;
  94.  
  95.  
  96. writeln;
  97. writeln;
  98. writeln('And tonights big money balls in ascending order are');
  99. writeln;
  100. writeln;
  101. writeln;
  102.  
  103.  
  104.  
  105. writeln(' *** ### ### ***');
  106. writeln(' *## ##*');
  107. writeln(' *## ##*');
  108. writeln(' *## ##*');
  109.  
  110. for k := 1 to 7 do
  111.  
  112. writeln(' *## ',k,': ',numbers[k],' ##*');
  113.  
  114.  
  115. writeln(' *## ##*'); {Displays the numbers in ascending order in a graphic}
  116. writeln(' *## ##*');
  117. writeln(' *## ##*');
  118. writeln(' *** ### ### *** ');
  119. writeln;
  120. writeln;
  121.  
  122.  
  123. end;
  124.  
  125. procedure search_for_numbers1 (numbers: a; user: b; var counter: integer);
  126. var
  127. q: integer;
  128. begin
  129. for q := 1 to 7 do {Seven seperate procedures that see if user numbers match lottery numbers}
  130. begin {If a match is found 1 is added to the counter}
  131. if user[1] = numbers[q] then
  132. counter := counter + 1;
  133. end;
  134. end;
  135.  
  136. procedure search_for_numbers2 (numbers: a; user: b; var counter: integer);
  137. var
  138. q: integer;
  139. begin
  140. for q := 1 to 7 do
  141. begin
  142. if user[2] = numbers[q] then
  143. counter := counter + 1;
  144. end;
  145. end;
  146.  
  147. procedure search_for_numbers3 (numbers: a; user: b; var counter: integer);
  148. var
  149. q: integer;
  150. begin
  151. for q := 1 to 7 do
  152. begin
  153. if user[3] = numbers[q] then
  154. counter := counter + 1;
  155. end;
  156. end;
  157.  
  158. procedure search_for_numbers4 (numbers: a; user: b; var counter: integer);
  159. var
  160. q: integer;
  161. begin
  162. for q := 1 to 7 do
  163. begin
  164. if user[4] = numbers[q] then
  165. counter := counter + 1;
  166. end;
  167. end;
  168.  
  169. procedure search_for_numbers5 (numbers: a; user: b; var counter: integer);
  170. var
  171. q: integer;
  172. begin
  173. for q := 1 to 7 do
  174. begin
  175. if user[5] = numbers[q] then
  176. counter := counter + 1;
  177. end;
  178. end;
  179.  
  180. procedure search_for_numbers6 (numbers: a; user: b; var counter: integer);
  181. var
  182. q: integer;
  183. begin
  184. for q := 1 to 7 do
  185. begin
  186. if user[6] = numbers[q] then
  187. counter := counter + 1;
  188. end;
  189. end;
  190.  
  191. procedure search_for_numbers7 (numbers: a; user: b; var counter: integer);
  192. var
  193. q: integer;
  194. begin
  195. for q := 1 to 7 do
  196. begin
  197. if user[7] = numbers[q] then
  198. counter := counter + 1;
  199. end;
  200. end;
  201.  
  202.  
  203.  
  204. procedure display_monies0 (counter: integer);
  205. begin
  206. if counter = 0 then
  207. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  208. if counter = 0 then
  209. writeln(' / \');
  210. if counter = 0 then
  211. writeln('| You have Matched ',counter,' Balls and Have Won Nothing ! |');
  212. if counter = 0 then
  213. writeln(' \ /');
  214. if counter = 0 then
  215. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  216. end;
  217.  
  218. { Seven seperate programs that assess value of counters and display prize money}
  219. {If counter = ?? then you have won ??}
  220. procedure display_monies1 (counter: integer);
  221. begin
  222.  
  223. if counter = 1 then
  224. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  225. if counter = 1 then
  226. writeln(' / \');
  227. if counter = 1 then
  228. writeln('| You have Matched ',counter,' Ball and Have Won 1 Pound |');
  229. if counter = 1 then
  230. writeln(' \ /');
  231. if counter = 1 then
  232. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  233. end;
  234.  
  235. procedure display_monies2 (counter: integer);
  236. begin
  237.  
  238. if counter = 2 then
  239. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  240. if counter = 2 then
  241. writeln(' / \');
  242. if counter = 2 then
  243. writeln('| You have Matched ',counter,' Balls and Have Won 5 Pounds |');
  244. if counter = 2 then
  245. writeln(' \ /');
  246. if counter = 2 then
  247. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  248. end;
  249.  
  250. procedure display_monies3 (counter: integer);
  251. begin
  252.  
  253. if counter = 3 then
  254. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  255. if counter = 3 then
  256. writeln(' / \');
  257. if counter = 3 then
  258. writeln('| You have Matched ',counter,' Balls and Have Won 10 Pounds |');
  259. if counter = 3 then
  260. writeln(' \ /');
  261. if counter = 3 then
  262. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  263. end;
  264.  
  265. procedure display_monies4 (counter: integer);
  266. begin
  267.  
  268. if counter = 4 then
  269. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  270. if counter = 4 then
  271. writeln(' / \');
  272. if counter = 4 then
  273. writeln('| You have Matched ',counter,' Balls and Have Won 5000 Pounds |');
  274. if counter = 4 then
  275. writeln(' \ /');
  276. if counter = 4 then
  277. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  278. end;
  279.  
  280. procedure display_monies5 (counter: integer);
  281. begin
  282.  
  283. if counter = 5 then
  284. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  285. if counter = 5 then
  286. writeln(' / \');
  287. if counter = 5 then
  288. writeln('| You have Matched ',counter,' Balls and Have Won 25,000 Pounds |');
  289. if counter = 5 then
  290. writeln(' \ /');
  291. if counter = 5 then
  292. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  293. end;
  294.  
  295.  
  296. procedure display_monies6 (counter: integer);
  297. begin
  298.  
  299. if counter = 6 then
  300. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  301. if counter = 6 then
  302. writeln(' / \');
  303. if counter = 6 then
  304. writeln('| You have Matched ',counter,' Balls and Have Won 375,000 Pounds |');
  305. if counter = 6 then
  306. writeln(' \ /');
  307. if counter = 6 then
  308. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  309. end;
  310.  
  311.  
  312. procedure display_monies7 (counter: integer);
  313. begin
  314.  
  315. if counter = 7 then
  316. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  317. if counter = 7 then
  318. writeln(' / \');
  319. if counter = 7 then
  320. writeln('| You have Matched ',counter,' Balls and Have Won 4,300,000 Pounds |');
  321. if counter = 7 then
  322. writeln(' \ /');
  323. if counter = 7 then
  324. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  325. end;
  326.  
  327.  
  328.  
  329. procedure show_prizes (i: integer);
  330.  
  331. begin
  332. writeln;
  333. writeln ('The prize monies for Tonights Game Is');
  334. writeln;
  335. writeln (' 0 Balls: 0 pounds');
  336. writeln (' 1 Ball: 1 pounds');
  337. writeln (' 2 Balls: 5 pounds');
  338. writeln (' 3 Balls: 10 pounds'); {A table of the prizes available}
  339. writeln (' 4 Balls: 5000 pounds');
  340. writeln (' 5 Balls: 25,000 pounds');
  341. writeln (' 6 Balls: 375,000 pounds');
  342. writeln (' 7 Balls: 4,300,000 pounds');
  343. end;
  344.  
  345.  
  346.  
  347. begin
  348. initialise(counter);
  349. get_user_numbers(user);
  350. start_game(i, numbers, k ,j, tmp);
  351. sort_nums(numbers, k, j, tmp);
  352. search_for_numbers1(numbers,user,counter);
  353. search_for_numbers2(numbers,user,counter);
  354. search_for_numbers3(numbers,user,counter);
  355. search_for_numbers4(numbers,user,counter);
  356. search_for_numbers5(numbers,user,counter);
  357. search_for_numbers6(numbers,user,counter);
  358. search_for_numbers7(numbers,user,counter);
  359. display_monies0(counter);
  360. display_monies1(counter);
  361. display_monies2(counter);
  362. display_monies3(counter);
  363. display_monies4(counter);
  364. display_monies5(counter);
  365. display_monies6(counter);
  366. display_monies7(counter);
  367. show_prizes(i);
  368. end.
Last edited by Narue; Jan 4th, 2009 at 9:15 am. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Lottery Validation

 
0
  #2
Jan 4th, 2009
Well, you seem to have grasped the if statement, what issues did you have when deciding wether all the numbers entered were between 1 and 49 (and I guess not used twice)
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,964
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 284
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Lottery Validation

 
0
  #3
Jan 4th, 2009
Correct but weird :
  1. procedure display_monies0 (counter: integer);
  2. begin
  3. if counter = 0 then
  4. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  5. if counter = 0 then
  6. writeln(' / \');
  7. if counter = 0 then
  8. writeln('| You have Matched ',counter,' Balls and Have Won Nothing ! |');
  9. if counter = 0 then
  10. writeln(' \ /');
  11. if counter = 0 then
  12. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  13. end;
Why not
  1. procedure display_monies0 (counter: integer);
  2. begin
  3. if counter = 0 then
  4. begin
  5. writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
  6. writeln(' / \');
  7. writeln('| You have Matched ',counter,' Balls and Have Won Nothing ! |');
  8. writeln(' \ /');
  9. writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
  10. end;
  11. end;
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: smorton123 is an unknown quantity at this point 
Solved Threads: 0
smorton123 smorton123 is offline Offline
Newbie Poster

Re: Lottery Validation

 
0
  #4
Jan 4th, 2009
The program first of all didnt recognise the valiation, then it did not work correctly with the array. Thats the part I am struggling with validation on an array. I can do validation on a variable but dont no where to start with an array ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Lottery Validation

 
0
  #5
Jan 4th, 2009
Have you tried a for loop on the array to work through each item?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: smorton123 is an unknown quantity at this point 
Solved Threads: 0
smorton123 smorton123 is offline Offline
Newbie Poster

Re: Lottery Validation

 
0
  #6
Jan 4th, 2009
Originally Posted by LizR View Post
Have you tried a for loop on the array to work through each item?
I have tried that but the program ran with no effect. I couldnt seem to get the loop to run with the array. Would you be able to show an example of how to validate/ loop with an array no matter how basic ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Lottery Validation

 
0
  #7
Jan 4th, 2009
How to validate it? thats kinda something I want you to work out, so..

Stepping through an array..
Pascal and Delphi Syntax (Toggle Plain Text)
  1. for i:=1 to 7 do
  2. begin
  3. writeln(a[i]);
  4. end;

So, that will write out your elements..
Now, see if you can add enough code to test if its valid or not.

You'll probably want 1 more variable, and you'll need your if statements..

See if you can tell me what you think it should be
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: smorton123 is an unknown quantity at this point 
Solved Threads: 0
smorton123 smorton123 is offline Offline
Newbie Poster

Re: Lottery Validation

 
0
  #8
Jan 4th, 2009
I dont actually have Pascal on this machine but here's a rough idea

Pascal and Delphi Syntax (Toggle Plain Text)
  1. for i:=1 to 7 do
  2. writeln (‘Please enter 7 numbers’)
  3. begin
  4. readln(a[i]);
  5. if [a] (< 1) or > (>7) the
  6. writeln (‘Please re-enter the number between 1 and 7)
  7. until [a] (=> 1 and <=7)
  8. end;

This is effectively what I want my program to do where it takes in seven numbers between X and Y. If any number exceeds this range then it displays an error message and will not accept that number until it fits into the specified range. But I know the validation is not correct.
Last edited by smorton123; Jan 4th, 2009 at 2:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Lottery Validation

 
0
  #9
Jan 4th, 2009
Well you're right in that that wouldnt work but you arent as far off as you think.

You ask for 7 numbers, thats fine.
the only part is wrong really is the if and until.. (as you're arent actually asking for a number you're just writing out please reenter the number.. but also an if and until dont go together.

You might want to read up on how the "until" function works, such as at http://delphibasics.co.uk/RTL.asp?Name=Until

But the general premise is OK, although [a] would fail, as would the (->1 and <=7) and theres no repeat with your until But the logic you have isnt that far wrong.

Read up on while loops too, theres a huge difference between them, but you may what whiles as well later
http://delphibasics.co.uk/RTL.asp?Name=While

See if you can work out what to do next
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: smorton123 is an unknown quantity at this point 
Solved Threads: 0
smorton123 smorton123 is offline Offline
Newbie Poster

Re: Lottery Validation

 
0
  #10
Jan 4th, 2009
Thanks for the help, some good stuff to learn. However could you please tell me what should go instead of the [a] as this is causing me the most trouble. Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC