Well, here is the program. I’ve only made the mode where it accepts AutoPlay - I can’t imagine anyone really wants to sit and press “G” or “B” 100 times. If its asked for I might do it though. The computer uses Cecil’s rules to “guess” the gender of the unknown child, if the known is a Girl, it picks boy and vice versa. As I suspected, the results hover around 50% (though I’ve seen as high as 59%, I’ve seen no where near 66% which is where it should hover if Cecil were right).
To run this program - copy and paste it into notepad. In notepad, do a file save as and type (the quotes are important) “C:\gender.bas” (or whatever filename and path you wish, so long as it has the .BAS extension and the quotes its fine). Then from the command line or the run programs box, type:
qbasic c:\gender.bas
Press F5 to run the program.
This code is very simple, hopefully anyone will be able to follow it. If anyone thinks what I have done is not relevant to the question, please explain why and suggest the necessary changes (in code if you can).
Enjoy!
DECLARE SUB ManualPlay ()
DECLARE SUB AutoPlay ()
’ Guess the Gender Game!
’ Courtesy of Cooper, for the SDMB and the interest of scientific advancement
DIM InitComplete AS INTEGER, GgCount AS INTEGER, bbcount AS INTEGER
DIM BgCount AS INTEGER, GbCount AS INTEGER, i AS INTEGER
DIM PlayResp AS STRING, NumberRight AS INTEGER
DIM SHARED array1(100) AS STRING, array2(100) AS STRING
'Initialize Families
RANDOMIZE TIMER
FOR i = 1 TO 100
IF RND > .5 THEN
array1(i) = "B"
ELSE
array1(i) = "G"
END IF
'Children's gender determined independently, just like in real life
'if we understood this part better, we could stop here
IF RND > .5 THEN
array2(i) = "B"
ELSE
array2(i) = "G"
END IF
NEXT i
'Now we check our pairs to ensure they are within tolerances
FOR i = 1 TO 100
IF array1(i) = "B" AND array2(i) = "B" THEN bbcount = bbcount + 1
IF array1(i) = "B" AND array2(i) = "G" THEN BgCount = BgCount + 1
IF array1(i) = "G" AND array2(i) = "B" THEN GbCount = GbCount + 1
IF array1(i) = "G" AND array2(i) = "G" THEN GgCount = GgCount + 1
NEXT i
'I'm going to print the totals at the outset, if you play in manual
'mode you could count but then you can count anyway because you have
'a pretty good idea what the breakdown will be. In any event the
'distribution should be even and
'I doubt if many are going to play in manual much.
'This way you could decide to start over if you feel its way too
'lopsided.
PRINT "BB: ", bbcount
PRINT "BG: ", BgCount
PRINT "GB: ", GbCount
PRINT "GG: ", GgCount
'Find out if the user wants to play manual or auto, and begin the game!
GetPlayInput:
INPUT "Play: (A)uto, (M)anual, or (Q)uit: ", PlayResp
SELECT CASE PlayResp
CASE “A”
AutoPlay
CASE “M”
ManualPlay
CASE “Q”
END
CASE “a”
AutoPlay
CASE “m”
ManualPlay
CASE “q”
END
CASE ELSE
GOTO GetPlayInput:
END SELECT
SUB AutoPlay
DIM i AS INTEGER, NumberRight AS INTEGER, Guess AS STRING
DIM numberlines AS INTEGER
PRINT “Known”, “Guessed”, “Correct Answer”
PRINT “------------------------------------------”
FOR i = 1 TO 100
'You can take this part out or comment it if you just want to run the program
'a bunch of times without a screen pause
IF numberlines = 20 THEN
PRINT “Press a key to continue…”
DO
LOOP UNTIL INKEY$ <> “”
numberlines = 0
END IF
IF array1(i) = “G” THEN Guess = “B”
IF array1(i) = “B” THEN Guess = “G”
IF Guess = array2(i) THEN NumberRight = NumberRight + 1
PRINT array1(i), Guess, array2(i)
numberlines = numberlines + 1
NEXT i
PRINT "I got “; NumberRight; " correct!”
END SUB
SUB ManualPlay
PRINT “This doesn’t exist. If you really think its needed then”
PRINT “write it yourself or pester me a bunch.”
END SU