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

Username:   Password: 
 RegisterRegister   
 Randomizing Varible! PLEASE HELP!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TopBypass




PostPosted: Tue Jan 22, 2008 7:59 pm   Post subject: Randomizing Varible! PLEASE HELP!

I have made variables (a, b and c) and now i need to have them be picked but completely randomly and i am using Rand.Int but it wont work!! I really need help with this its for a final!! Thank you sooo much!
Sponsor
Sponsor
Sponsor
sponsor
michaelp




PostPosted: Tue Jan 22, 2008 8:03 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

What do you mean by "won't work?" Is is the same number every time, a, b, and c are all the same? Did you test the variables using "put a" or "put b" or "put c"?
If you want them completely random, just use the arguments 1 and a really big number.
Gooie




PostPosted: Tue Jan 22, 2008 8:03 pm   Post subject: Re: Randomizing Varible! PLEASE HELP!

Use something like this.

code:

RandomChoice := Rand.Int (1, 3)

if RandomChoice = 1 then
    put "cat"
elsif RandomChoice = 2 then
    put "dog"
elsif RandomChoice = 3 then
    put "fish"
end if


A case would be better though.
TopBypass




PostPosted: Tue Jan 22, 2008 8:24 pm   Post subject: Re: Randomizing Varible! PLEASE HELP!

Still wont work, im getting an error. This is what i am trying to do:

Write a program that plots points at A(300, 50), B(50, 500) and C(550, 500) - I finished this here is how i did it:

code:
Draw.Dot (300, 50, black)
Draw.Dot (50, 500, black)
Draw.Dot (550, 500, black)


Now i need to:
randomly choose either A, B or C (lets say it was A) and plot a new point, Q, which is half way between P and A.
TopBypass




PostPosted: Tue Jan 22, 2008 8:38 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

Im still confused and i really do need this as quickly as possible so please help me! Thank you!
TopBypass




PostPosted: Tue Jan 22, 2008 8:49 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

Alright i messed up something. Here is what i need from the start. I need to plot a point called A as a variable. A has to be a certain point BUT I HAVE NOOOO IDEA HOW TO DO THIS. I have tried making its value Draw.Dot (number, number, color) but that wont work either.
Gooie




PostPosted: Tue Jan 22, 2008 9:06 pm   Post subject: Re: Randomizing Varible! PLEASE HELP!

Alright, well what data type are is A?
TopBypass




PostPosted: Tue Jan 22, 2008 9:16 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

I defined it as an int
Sponsor
Sponsor
Sponsor
sponsor
Gooie




PostPosted: Tue Jan 22, 2008 9:25 pm   Post subject: Re: Randomizing Varible! PLEASE HELP!

Your first problem is that an Integer can't store two values (an ordered pair (x,y)).
TopBypass




PostPosted: Tue Jan 22, 2008 9:26 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

Also do you know how to use putpixel? It says i am too use it but i cannot find it in turing.
TopBypass




PostPosted: Tue Jan 22, 2008 9:31 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

What would i use than? Would a string work?
Gooie




PostPosted: Tue Jan 22, 2008 9:33 pm   Post subject: Re: Randomizing Varible! PLEASE HELP!

I don't believe putpixel exists in Turing. I searched documentation, the internet, compsci, and I can declare a variable by that name. Are you sure your teacher isn't confused with another language?
TopBypass




PostPosted: Tue Jan 22, 2008 9:35 pm   Post subject: Re: Randomizing Varible! PLEASE HELP!

Alright so far i can pick a random point and a random variable in which case it draws a dot in its location. Here is the code for that.

code:
var int_ax :int := 300
var int_ay :int := 50
var int_bx :int := 50
var int_by :int := 500
var int_cx :int := 550
var int_cy :int := 500
var int_p :int := Rand.Int (1, 1000)
var random :int := Rand.Int (1, 3)


Draw.Dot (int_ax, int_ay, black) %This is my A
Draw.Dot (int_bx, int_by, black) %This is my B
Draw.Dot (int_cx, int_cy, black) %This is my C

Draw.Dot (int_p, int_p, black) %This is my P

loop
if random = 1 then
    Draw.Dot (int_ax, int_ay, black)
end if
if random = 2 then
    Draw.Dot (int_bx, int_by, black)
end if
if random = 2 then
    Draw.Dot (int_cx, int_cy, black)
end if
end loop


Now what i want to do is make it so when it picks a random point (A or B or C) it makes a dot in between P and the randomly choicen one.

EDIT: It might be but its his exact type. "Pick a random point to start, call it P and plot it using putpixel"
TopBypass




PostPosted: Tue Jan 22, 2008 9:41 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

Also the midpoint can be found by following this equation:

Posted Image, might have been reduced in size. Click Image to view fullscreen.
TopBypass




PostPosted: Tue Jan 22, 2008 9:44 pm   Post subject: RE:Randomizing Varible! PLEASE HELP!

I think i have found one of my problems. I have giving int_p a specific Rand.Int point. Instead i need it to form anywhere on the page. Is this possible?

EDIT: By the way you have been a great help! Just wanted to say that it is not going unnoticed and i am completely grateful Smile
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 2  [ 23 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: