EasyManua.ls Logo

Commodore 128D - SECTION 6 - Color, Animation and Sprite Graphics Statements Unique to the C128

Commodore 128D
448 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
? INT((100/6)+0.5) n m iw i
You can substitute any calculation for the division shown in the
inner parentheses.
What if you want to round off numbers to the nearest 0.01 ?
Instead of adding 0.5 to your number, add 0.005, then multiply by
100. Let’s say you want to round 2.876 to the nearest 0.01. Using
this method, you start with:
? (2.876 + 0.005) *100
Now use the INT function to get rid of everything after the
decimal point (which moves two places to the right when you
multiply by 100). You are left with:
? INT((2.876 + 0.005)*100) HEIUIIII
which gives you a value of 288. All that’s left to do is divide by
100 to get the value of 2.88, which is the answer you want. Using
this technique, you can round off calculations like the following to
the nearest 0.01:
? INT(((2.876+1.29+16.1 â–  9.534)+0.005)
Generating Random Numbers—The RND Function
The RND functions tells the computer to generate a random
number. This can be useful in simulating games of chance, and
in creating interesting graphic or music programs. All random
(RND) numbers are nine digits, in decimal form, between the
values 0.000000001 and 0.999999999. Type:
? RND (0) BB-yflW
Multiplying the randomly generated number by six makes the
range of generated numbers increase to greater than 0 and less
than 6. ln order to include 6 among the numbers generated, we
add one to the result of RND(0)*6. This makes the range 1<X<7.
If we use the INT function to eliminate the decimal places, the
command will generate whole numbers from 1 to 6. This process
can be used to simulate the rolling of a die. Try this program:
10 R= (INT(RND(1)*6+1)
20 ? R
30 GOTO 10
4-21

Table of Contents

Other manuals for Commodore 128D

Related product manuals