Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a Timer to flip coin and print

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i need to know how to generate a totall random set of numbers there should be 10 numbers pulled (only two choices 2,1, head and tails) then i need to be able and tell how many times it landed on 1(heads) and 2(Tails)
This is what iv'e got so far... i can't get it to print how many tails and how many heads


COLOR 14,9 '** HA my colors
CLS
FOR X = 1 TO 10 '**10 flips
RANDOMIZE TIMER
? INT(RND * (2 - 1) + 1 '**choices are
'**1(tails) 2(Heads)

NEXT
END


I am hoping to have it look something like this:

TAILS HEADS
----- -----
(amount of 1'a landed) (Amount of 2's landed)

THaNKX
chris
 
Think of it like this:
* There is one pile of coins where they turned out to be heads. The size of the file is stored in variable H.
* There is another pile of coins that flipped to be tails. The size of that pile is stored in variable T.


So what happens when we get heads? The size of the Head coin pile increases by 1. So H = H + 1.

What happens when we get tails? The size of the Tail coin pile increases by 1. So T = T + 1.

When you're done flipping coins, you can display the values of H and T. For more information, read the help menu on the PRINT statement.

By the way, INT(RND * (2 - 1) + 1 won't give you an even distribution of heads and tails. That's because RND*1 returns a random value between 0 and 0.999999999... I think what you want is x = INT(RND * 1 + 1.5)

Good luck finishing your program.
 
try this code:

FOR X = 1 TO 10
RANDOMIZE TIMER
side = INT(RND*(2-1)+1
IF side = 1 THEN tails = tails+1
IF side = 2 THEN heads = headS+1
NEXT
PRINT "TAILS","HEADS"
PRINT tails,heads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top