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

Username:   Password: 
 RegisterRegister   
 What should I do to make this
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
thomasb




PostPosted: Tue Jan 25, 2011 11:52 am   Post subject: What should I do to make this

How would you make this program:
Write a program to generate 10 random real numbers between:
a. 4 and 5
b. 0 and 10
c. 20 and 30
d. X any y where x and y are integer inputs

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jan 25, 2011 12:36 pm   Post subject: RE:What should I do to make this

One step at a time.

How would you generate a random (any range) real number? Do that 10 times. Use basic arithmetic operations to transform the range to satisfy a,b,c... which are all just specific cases of d.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
RandomLetters




PostPosted: Tue Jan 25, 2011 2:18 pm   Post subject: RE:What should I do to make this

dont we have Rand.Int()?
Tony




PostPosted: Tue Jan 25, 2011 2:30 pm   Post subject: RE:What should I do to make this

We do! We even have the documentation on how it works and how to use it -- Rand.Int
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Thu Feb 17, 2011 8:41 pm   Post subject: RE:What should I do to make this

here, i'll make it simple.

So you have 2 options, which are basically the same thing.

Lets say the variable was x.

1) x := Rand.Int (a, b)

2) randint (x, a, b)

a and b are just the parameters. If you wanted a random number between 1 and 10, you would replace a with 1 and b with 10.
Either way wont really matter; The only time it would matter is when you have a compund var statement with the same random number like this:

var a, b, c : int := Rand.Int (1, 3)

anyways, hope that helps.
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: