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

Username:   Password: 
 RegisterRegister   
 How can I store data with randint?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
user23




PostPosted: Thu May 12, 2011 9:47 pm   Post subject: How can I store data with randint?

So I am trying to store data using random integers with the following code:
loop
randint (x, 1, 100)
randint (y, 1, 200)
if item (x,y) = 0 then
item (x,y) :=1
itemcount := itemcount +1
end if
exit when itemcount = 10
end loop

so using that code, shouldn't x, y in item (x,y) be replaced with the random integers, and then the value of the specific random integers receive the +1? Currently, even using that code, while trying to check the value of (x,y) within a for loop, every single item (x,y) = 1, which I assume is because of that line not storing the data for the random integers, but just the variables? So my question is, how should I change / fix this, so that the values are stored for specific random integers?

Thanks
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu May 12, 2011 9:53 pm   Post subject: RE:How can I store data with randint?

what is "item" defined as?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
user23




PostPosted: Fri May 13, 2011 6:24 am   Post subject: Re: How can I store data with randint?

item is an array

code:
var item : array 1 .. 100, 1 .. 200 of int
mirhagk




PostPosted: Fri May 13, 2011 8:41 am   Post subject: RE:How can I store data with randint?

your checking if the (x,y)th element of item is 0, so is there a case where it isn't 0?
tyuo9980




PostPosted: Fri May 13, 2011 8:35 pm   Post subject: Re: How can I store data with randint?

the problem in your code is that you're just naming the element. you're not actually assigning anything to that element.

for i : 1 .. 10
randint x,1,5
arrayx (i) := x
end for
user23




PostPosted: Fri May 13, 2011 9:08 pm   Post subject: Re: How can I store data with randint?

edit
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  [ 6 Posts ]
Jump to:   


Style:  
Search: