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.
{Note - Validation should occur in the procedure 'get user numbers' . I have removed any attempts so its easier to see}
program test;
uses
EmptyPlaceHolderUnit;
type
a = array[1..7] of integer; {Starts an array that will store the random numbers created by the lottery}
b = array[1..7] of integer; {Starts an array that will store the users seven lottery numbers}
var
i : integer;
k, j, tmp: integer;
numbers: a;
user: b;
counter: integer;
var
subscript: integer;
q: integer;
procedure initialise (var counter: integer);
begin
counter := 0; {Starts Counter}
end;
procedure get_user_numbers (var user: b);
begin
writeln ;
writeln( ' You are now playing the Lottery Game ' );
writeln ;
write('Could You Please Select Your Seven Lottery Numbers Between the Range 0 - 49 ');
writeln;
for subscript := 1 to 7 do
begin {Gets user to enter their selected lottery Numbers}
readln(user[subscript]); {Stores User Numbers in the array 'user'}
end;
end;
procedure start_game (i:integer; var numbers: a; k ,j, tmp: integer);
var
q: integer;
begin
writeln;
writeln (' ,---'); {Starting Game Graphic}
writeln (' ( -_-('); {Due to limitations of the interface in Pascal}
writeln (' ) .__/ )'); {I used ASCII art to create a graphic relevant to the game}
writeln (' _/ _/_( / _.---._');
writeln (' (__/ _ _) ,-._ / o \');
writeln (' //)__(\/,-` |_| O o o O|');
writeln ('_\\///==o=\'' | O o o O |');
writeln (' `-''\ / \O o o /');
writeln (' )___\ `''-.-\\');
writeln (' / ,\ \ ____)_(____');
writeln (' / / \ \ ''--..---,,-- ');
writeln (' /() >() \\_//');
writeln (' |\_\ |\_\ /,-.\');
writeln ;
writeln (' And tonights Lottery Balls are...');
writeln ;
begin
randomize;
for q := 1 to 7 do
begin
numbers[q] := (random(50)); {Selects and displays 7 random integers from the range 0 - 49}
write(numbers[q],' ');
end;
end;
end;
procedure sort_nums ( numbers: a; k, j, tmp: integer);
var
q: integer;
begin
for k := 1 to 6 do
for j := k + 1 to 7 do
if numbers[k] > numbers[j] then {Sorts numbers into ascending order}
begin
tmp := numbers[k];
numbers[k] := numbers[j];
numbers[j] := tmp;
end;
writeln;
writeln;
writeln('And tonights big money balls in ascending order are');
writeln;
writeln;
writeln;
writeln(' *** ### ### ***');
writeln(' *## ##*');
writeln(' *## ##*');
writeln(' *## ##*');
for k := 1 to 7 do
writeln(' *## ',k,': ',numbers[k],' ##*');
writeln(' *## ##*'); {Displays the numbers in ascending order in a graphic}
writeln(' *## ##*');
writeln(' *## ##*');
writeln(' *** ### ### *** ');
writeln;
writeln;
end;
procedure search_for_numbers1 (numbers: a; user: b; var counter: integer);
var
q: integer;
begin
for q := 1 to 7 do {Seven seperate procedures that see if user numbers match lottery numbers}
begin {If a match is found 1 is added to the counter}
if user[1] = numbers[q] then
counter := counter + 1;
end;
end;
procedure search_for_numbers2 (numbers: a; user: b; var counter: integer);
var
q: integer;
begin
for q := 1 to 7 do
begin
if user[2] = numbers[q] then
counter := counter + 1;
end;
end;
procedure search_for_numbers3 (numbers: a; user: b; var counter: integer);
var
q: integer;
begin
for q := 1 to 7 do
begin
if user[3] = numbers[q] then
counter := counter + 1;
end;
end;
procedure search_for_numbers4 (numbers: a; user: b; var counter: integer);
var
q: integer;
begin
for q := 1 to 7 do
begin
if user[4] = numbers[q] then
counter := counter + 1;
end;
end;
procedure search_for_numbers5 (numbers: a; user: b; var counter: integer);
var
q: integer;
begin
for q := 1 to 7 do
begin
if user[5] = numbers[q] then
counter := counter + 1;
end;
end;
procedure search_for_numbers6 (numbers: a; user: b; var counter: integer);
var
q: integer;
begin
for q := 1 to 7 do
begin
if user[6] = numbers[q] then
counter := counter + 1;
end;
end;
procedure search_for_numbers7 (numbers: a; user: b; var counter: integer);
var
q: integer;
begin
for q := 1 to 7 do
begin
if user[7] = numbers[q] then
counter := counter + 1;
end;
end;
procedure display_monies0 (counter: integer);
begin
if counter = 0 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 0 then
writeln(' / \');
if counter = 0 then
writeln('| You have Matched ',counter,' Balls and Have Won Nothing ! |');
if counter = 0 then
writeln(' \ /');
if counter = 0 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
{ Seven seperate programs that assess value of counters and display prize money}
{If counter = ?? then you have won ??}
procedure display_monies1 (counter: integer);
begin
if counter = 1 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 1 then
writeln(' / \');
if counter = 1 then
writeln('| You have Matched ',counter,' Ball and Have Won 1 Pound |');
if counter = 1 then
writeln(' \ /');
if counter = 1 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
procedure display_monies2 (counter: integer);
begin
if counter = 2 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 2 then
writeln(' / \');
if counter = 2 then
writeln('| You have Matched ',counter,' Balls and Have Won 5 Pounds |');
if counter = 2 then
writeln(' \ /');
if counter = 2 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
procedure display_monies3 (counter: integer);
begin
if counter = 3 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 3 then
writeln(' / \');
if counter = 3 then
writeln('| You have Matched ',counter,' Balls and Have Won 10 Pounds |');
if counter = 3 then
writeln(' \ /');
if counter = 3 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
procedure display_monies4 (counter: integer);
begin
if counter = 4 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 4 then
writeln(' / \');
if counter = 4 then
writeln('| You have Matched ',counter,' Balls and Have Won 5000 Pounds |');
if counter = 4 then
writeln(' \ /');
if counter = 4 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
procedure display_monies5 (counter: integer);
begin
if counter = 5 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 5 then
writeln(' / \');
if counter = 5 then
writeln('| You have Matched ',counter,' Balls and Have Won 25,000 Pounds |');
if counter = 5 then
writeln(' \ /');
if counter = 5 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
procedure display_monies6 (counter: integer);
begin
if counter = 6 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 6 then
writeln(' / \');
if counter = 6 then
writeln('| You have Matched ',counter,' Balls and Have Won 375,000 Pounds |');
if counter = 6 then
writeln(' \ /');
if counter = 6 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
procedure display_monies7 (counter: integer);
begin
if counter = 7 then
writeln(' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\');
if counter = 7 then
writeln(' / \');
if counter = 7 then
writeln('| You have Matched ',counter,' Balls and Have Won 4,300,000 Pounds |');
if counter = 7 then
writeln(' \ /');
if counter = 7 then
writeln(' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/');
end;
procedure show_prizes (i: integer);
begin
writeln;
writeln ('The prize monies for Tonights Game Is');
writeln;
writeln (' 0 Balls: 0 pounds');
writeln (' 1 Ball: 1 pounds');
writeln (' 2 Balls: 5 pounds');
writeln (' 3 Balls: 10 pounds'); {A table of the prizes available}
writeln (' 4 Balls: 5000 pounds');
writeln (' 5 Balls: 25,000 pounds');
writeln (' 6 Balls: 375,000 pounds');
writeln (' 7 Balls: 4,300,000 pounds');
end;
begin
initialise(counter);
get_user_numbers(user);
start_game(i, numbers, k ,j, tmp);
sort_nums(numbers, k, j, tmp);
search_for_numbers1(numbers,user,counter);
search_for_numbers2(numbers,user,counter);
search_for_numbers3(numbers,user,counter);
search_for_numbers4(numbers,user,counter);
search_for_numbers5(numbers,user,counter);
search_for_numbers6(numbers,user,counter);
search_for_numbers7(numbers,user,counter);
display_monies0(counter);
display_monies1(counter);
display_monies2(counter);
display_monies3(counter);
display_monies4(counter);
display_monies5(counter);
display_monies6(counter);
display_monies7(counter);
show_prizes(i);
end.