Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 using randint, Help asap, isp due tomoro!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
johnbobbit




PostPosted: Sat Jan 17, 2004 8:08 pm   Post subject: using randint, Help asap, isp due tomoro!!

I am doing an isp which requires the usage of arrays, which i dont understand well.
i have to make 5 different sized blocks each a different color appear on the screen in random order.
I am able to make one square come out and each time it changes size and colour.
now i need to get all of it's 5 forms to come out in random order. Thats the part i am stuck on and i've tried everything for about 6 hours now.
if any body can help plz correct and guide me.
here is the userInput part of my program code:


var num : array 1 .. 5 of int
var coord : array 1 .. 5 of int
randomize
var box : array 1 .. 5 of int := init (60, 80, 100, 120, 140)
var boxEndx : array 1 .. 5 of int := init (0, 0, 0, 0, 0)
var boxEndy : array 1 .. 5 of int := init (60, 80, 100, 120, 140)
var c : int := 0
var x : int := 0
var f : string (1)


procedure userInput
randomize
for y : 1 .. 5
randomize
x := x + 1
randint (num (x), 1, 5)

put (num (x))

exit when x > 5
randint (num (x), 1, 5)

if num (x) = 1 then
c := 7
elsif num (x) = 2 then
c := 9
elsif num (x) = 3 then
c := 12
elsif num (x) = 4 then
c := 14
else
c := 5
end if
end for
for a : 1 .. 5
for s : 1 .. 5
for y : 1 .. 5
x := x + 1
drawfillbox (100, 100, box (num (y)) + boxEndy (num (y)), box (num (y)) + box (num (y)), c)
end for
end for
end for
end userInput
Sponsor
Sponsor
Sponsor
sponsor
DanShadow




PostPosted: Sat Jan 17, 2004 9:49 pm   Post subject: (No subject)

k...first of all, you dont need to post the same post twice, just leave one, and wait for it to be answered. Secondly, dont name posts like "I NEED HELP ON THIS F*CKEN BITCH!!" of whatever it was. (This post title is good though.) With seeing two p osts with the same thing, I decided not to read your post, and just explain arrays to you, fair enough.
code:

%Declares an array with the name "numbers" with ten integers in it
var numbers:array 1..10 of int
%In a for statement, each integer in the "numbers" array is assigned a
%number, which is equal to "i"
for i:1..10
numbers(i):=i
end for
%In a for statement, it displays the values of all the integers in the
%"numbers" array
for i:1..10
put "Numbers(",i,")= ",numbers(i)
end for
%Makes the fifth integer in the "numbers" array equal to 8
numbers(5):=8

Thats how an array works...if you need more information, ask specifically, and nicely. Smile
This can be manipulated like so:
code:

var x,y:array 1..3 of int
x(1):=100
y(1):=100
x(2):=300
y(2):=200
x(3):=500
y(3):=300
for i:1..3
Draw.Box(x(i)-10,y(i)-10,x(i)+10,y(i)+10,255)
end for
johnbobbit




PostPosted: Sun Jan 18, 2004 3:19 pm   Post subject: It is still the same

I need to randomize in the order which each block comes out
recneps




PostPosted: Sun Jan 18, 2004 4:20 pm   Post subject: (No subject)

so have a randint make a random number, and have it call up the boxsize of that nuber in the array, like

randint(rand,1,5)

and whatever it gives, tell it to call up that siz box..

drawbox(x(rand),y(rand),(x(rand)+50),(y(rand)+50),7)

thatd make a box that is at the position that you randomized, and make it 50 by 50 pixels. understand?
johnbobbit




PostPosted: Sun Jan 18, 2004 4:46 pm   Post subject: Thanks for the reply

Yes i understand that and i have wrote the new userInput procedure.
The problem is that i need the 5 boxes which are differently sized, to come out in different order each time. so onece the largest may come first or second, or third or fourth or last. This goes for all the boxes.

Heres the userInput procedre:

%user input
procedure userInput
var x : array 1 .. 5 of int := init (60, 80, 100, 120, 140)
var y : array 1 .. 5 of int := init (60, 80, 100, 120, 140)
var space : array 1 .. 5 of int := init (-50, 20, 110, 220, 350)
for i : 1 .. 5
drawfillbox (space (i) + x (i), 200, space (i) + x (i) + x (i), y (i) + 200, i)
end for
end userInput
userInput
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: