
-----------------------------------
Arrow
Wed Feb 12, 2003 4:55 pm

Decimals?
-----------------------------------
Noob question here...
how do i make "randint(x,y,z)" generate a number with a certain number of decimals? not just a whole number...

btw x, y, and z are declared: "var x:int"

-----------------------------------
azndragon
Wed Feb 12, 2003 5:33 pm


-----------------------------------
Setting your variables as real type would help :D

-----------------------------------
Tony
Wed Feb 12, 2003 5:53 pm


-----------------------------------
rand(x:real)
will assign a random floating point (decimal) number between 0 and 1 to variable x

to get a value you want from it, you add the lower range and multiply by highrange - lowrange.

here's what I mean... say you want a 50 to 100 range.
so you do:

rand(x)
x:=x*(highrange-lowrange)+lowrange


where highrange would be 100 and lowrange would be 50

this code will assign a real value to x from 50 to 100.

-----------------------------------
Arrow
Wed Feb 12, 2003 10:56 pm


-----------------------------------
Hmm, thanks for the replys, still dont really understand though...
Heres my code:

var x:int
var y:int
var a:int
put "Enter the Minimum Value"
get x
put "Enter the Highest Value"
get y
randint(a,x,y)
put "A random number between these two is ", a

How would I go about changing x into a "real" number?
var x:real doesnt work

-----------------------------------
Tony
Thu Feb 13, 2003 9:49 am


-----------------------------------
thats because randint fuction generates a random integer (whole) value, not real. you have to use rand() to generate a random real number between 0 and 1.


var low:real
var high:real
var x:real

rand(x)
x:=x*(high-low)+low
put "a random number between ", low," and ",high," is ", x


-----------------------------------
Dan
Thu Feb 13, 2003 4:07 pm

a bit more
-----------------------------------
i just whonted to add on to this for poleop who did not know.

an int or intager is a number with no decliampe places (whole number).

ie. 56

an real number is a number with declmale  places.

ie. 56.56789


to decaler an var as an int (a var that will only take whole numbers):


var nameofvar:int


to decaler an var as real (a var that has decalmal numbers):


var nameofvar:real


you are going to decaler your veriables as  real if you whont to us the rand() comand to get random numbers with random decmail dlaces.

-----------------------------------
Tony
Thu Feb 13, 2003 5:18 pm


-----------------------------------
hah, thats what I love about C++, you can promote your variables in the program and your integer will turn into real if you do an operation with it containing a real number.

No more type mismatches  :D

*caugh*This is getting off topic :?

-----------------------------------
Dan
Fri Feb 14, 2003 7:28 am


-----------------------------------
ya that is nice. the ony porblem is when going from float to int it will not rownd just cut off the decmals, but it is still better then turings sytem.  :)

-----------------------------------
Tony
Fri Feb 14, 2003 9:18 am


-----------------------------------
oh, I'm fine with that... if you want to have it round floating point instead of dropping the decimal, you just add 0.5 before converting. It will be rounded perfectly  :D

-----------------------------------
*GoGeTa*
Mon Oct 18, 2004 5:21 pm

Hey do you need help
-----------------------------------
tell me exactly what you need help on adn send me your program .... i'll try to help

-----------------------------------
wtd
Mon Oct 18, 2004 6:13 pm


-----------------------------------
hah, thats what I love about C++, you can promote your variables in the program and your integer will turn into real if you do an operation with it containing a real number.

No more type mismatches  :D

*caugh*This is getting off topic :?

That behavior in C, C++ and various other languages causes a lot of problems, actually.

-----------------------------------
Cervantes
Tue Oct 19, 2004 9:17 am


-----------------------------------
is that the 'goto' of C/C++?  I wonder what kind of problems you are talking about, though: problems with coding it or problems with that method generally being frowned upon (like goto)

-----------------------------------
wtd
Tue Oct 19, 2004 1:20 pm


-----------------------------------
Well, it's generally preferable for your compiler to point out the fact that you're using an integer where you intended a floating point number to be used.  It allows you to find that semantic (rather than syntactic) error right away, rather than waiting until it becomes a problem.

-----------------------------------
Dan
Wed Oct 20, 2004 10:24 pm

Re: Hey do you need help
-----------------------------------
tell me exactly what you need help on adn send me your program .... i'll try to help


ummm guys this post was made like a year ago
