Pascal : Random Num Generator

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

Pascal : Random Num Generator

 
0
  #1
Nov 22nd, 2008
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.
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: Pascal : Random Num Generator

 
0
  #2
Nov 22nd, 2008
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?
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: Pascal : Random Num Generator

 
0
  #3
Nov 22nd, 2008
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.
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: Pascal : Random Num Generator

 
0
  #4
Nov 22nd, 2008
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.
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