| | |
Pascal : Random Num Generator
![]() |
•
•
Join Date: Nov 2008
Posts: 8
Reputation:
Solved Threads: 0
I'm making a project in Xcode Pascal, the program asks the user if they want to begin then selects seven random in a 'lottery' style game. I wanted to save the numbers into an array so I could select any one of the seven numbers at one time. At the moment I cannot get the program to read the numbers or save them. I know how to use arrays but I cant seem to get them to work for this program. Any help would be greatly appreciated.
program test;
uses
EmptyPlaceHolderUnit;
var
yn : string;
i : integer;
bonus: integer;
procedure start_game (yn: string; i:integer; bonus: integer);
var
subscript: integer;
begin
writeln('Do you want to begin? Please enter Y / N ( Remember to use capital letters! )'); {asks user if they want to begin}
readln(yn);
if (yn = 'Y') then {Will begin program if 'Yes' is entered}
writeln ('The program will now begin') else {Program will end if 'No' is entered}
writeln('You have chosen not to run the program');
if (yn = 'Y') then
begin
writeln (' ');
writeln (' And tonights Lottery Balls are...');
writeln (' ');
randomize;
for i := 1 to 7 do
writeln(random(50),' '); {Selects 6 random integers from the range 0 - 49}
writeln(i);
end;
end;
begin
start_game(yn, i, bonus);
end.
program test;
uses
EmptyPlaceHolderUnit;
var
yn : string;
i : integer;
bonus: integer;
procedure start_game (yn: string; i:integer; bonus: integer);
var
subscript: integer;
begin
writeln('Do you want to begin? Please enter Y / N ( Remember to use capital letters! )'); {asks user if they want to begin}
readln(yn);
if (yn = 'Y') then {Will begin program if 'Yes' is entered}
writeln ('The program will now begin') else {Program will end if 'No' is entered}
writeln('You have chosen not to run the program');
if (yn = 'Y') then
begin
writeln (' ');
writeln (' And tonights Lottery Balls are...');
writeln (' ');
randomize;
for i := 1 to 7 do
writeln(random(50),' '); {Selects 6 random integers from the range 0 - 49}
writeln(i);
end;
end;
begin
start_game(yn, i, bonus);
end.
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
You have no array in your program - however, your use of random is ok. So, Id argue a difference about using arrays as it seems to be this you're having the issue with.
OK, take it back a stage, how would you assign the numbers 1 through 10 to an array holding 10 integers?
OK, take it back a stage, how would you assign the numbers 1 through 10 to an array holding 10 integers?
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.
•
•
Join Date: Nov 2008
Posts: 8
Reputation:
Solved Threads: 0
I have a seperate program where I was toying about with an array so I know that works fine. What I did to get the program to work was to get the program to ask the user to enter the numbers back into the prgram. The users input was then stored in the array. I would like this to be tidied up and automatic though.
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
OK, but write me the code I asked, and then see if the bell tolls and you work out whats missing. as you're close, but without any array concept no its not going to.
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.
![]() |
Other Threads in the Pascal and Delphi Forum
- Previous Thread: delphi
- Next Thread: Report Application Pascal
| Thread Tools | Search this Thread |






