943,813 Members | Top Members by Rank

Ad:
Nov 22nd, 2008
0

Pascal : Random Num Generator

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smorton123 is offline Offline
8 posts
since Nov 2008
Nov 22nd, 2008
0

Re: Pascal : Random Num Generator

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?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Nov 22nd, 2008
0

Re: Pascal : Random Num Generator

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smorton123 is offline Offline
8 posts
since Nov 2008
Nov 22nd, 2008
0

Re: Pascal : Random Num Generator

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.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: delphi
Next Thread in Pascal and Delphi Forum Timeline: Report Application Pascal





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC