Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Who here is VERY good at troubleshooting QB programs?
#52
I don't have a solution to your problem, just a few questions/comments:

1. What exactly is the algorithm you want to use when calculating the probability, ie. in plain english?

2. Do try and give meaningful names to your variables. 'X' and the like don't provide any information on the type or contents, and only work to confuse those reading the code.

3. I've reworked the code for readability. I'm still unsure about certain parts:
Code:
defint a-z

const MAXSETS = 10
const MAXENTRIES = 10

dim entries( MAXSETS, MAXENTRIES )        '' entry array
dim totalsets as integer                  '' # of sets entered by user

dim occurances( 1 to 52 ) as integer      '' # of repetitions of numbers 1..52

dim NTH(1 to 10)                          '' ???
dim nx(1 to 52)                           '' ???

'' - main program ---------------------------------------------------------- ''
   '' [ ...display welcome screen... ]
  
   '' main loop
   dim place as integer : place = 0
   do
      if place = 0 then gosub MainMenu
      if place = 1 then gosub NUMBERS
      if place = 2 then gosub CalculateProbability
      if place = 3 then gosub Save
      if place = 4 then gosub Load
      if place = 5 then exit do           '' exit the loop ...
   loop

   '' [ ...display ending text/perform any cleanup necessary... ]

   sleep : end

'' - main menu ------------------------------------------------------------- ''
MainMenu:
   '' [ ...display main menu screen... ]

   do
      input place : place = int( place )
   loop until( place > 0 ) and ( place < 6 )
return

'' - get entries from user ------------------------------------------------- ''
NUMBERS:
   '' [ ...display number entry instructions... ]

   dim setindex as integer : setindex = 0
   while( setindex < MAXSETS )
      
      '' [ ...get entries as before... ]
      '' entries( setindex, ... ) = ...

      setindex = setindex + 1
      dim done as string
      do
         input "Enter another set?( y/n )"; done : done = lcase$( done )
         if( done = "n") then
            totalsets = setcount
            place = 0 : return
         end if
      loop until done = "y"
   wend
   place = 0
return

'' - calculate probability ------------------------------------------------- ''
CalculateProbability:
   print "GETTING THE PROBABILITY OF THE NUMBERS(MOST COMMON)."
  
   dim currentset as integer
   dim currententry as integer
   for currentset = 0 to totalsets - 1    '' <- iterate through total sets ( not 10 )
      for currententry = 0 to MAXENTRIES - 1
         dim entry as integer : entry = entries( currentset, currententry )
         if( entry = 0 ) then exit for    '' <- assuming zero ends the entry list
         occurances( entry ) = occurances( entry ) + 1
      next
   next
  
   dim i as integer
   for i=1 to 10 : nth(i) = 0 : next      '' clear these arrays, whatever
   for i=1 to 52 : nx(i) = 0 : next       '' "nth" and "nx" is supposed to mean
  
   dim picked as integer : picked = 0
   for Z = 1 to 10

      for i=1 to 24
         if( picked < occurances( i ) ) and ( nx( i ) = 0 ) then
            picked = i
            nx( i ) = 1
         end if
      next

      for i=25 to 52     '' <- Why are we treating 25-52 differently ?
         if( picked < occurances( i ) ) then
            flag = 0
            for j = 1 to 10
               if( nth( j ) = occurances( i ) ) then flag = 1 : exit for
            next
            if( flag = 0 ) then picked = i
         end if
      next

      nth( z ) = picked

      print Z
      print picked
      sleep 10
  
   next Z
   '' [ ...display the information... ]

   place = 0
return

'' - saving/loading -------------------------------------------------------- ''
dim FileName as string
dim FileHandle as integer     '' let QB decide what file handle to use
dim n as integer              '' iterator for occurances array

Save:
   input "Enter file to save, w/o extension: "; FileName
   FileName = FileName + ".txt"
   FileHandle = freefile
   open FileName for output as #FileHandle

   for n = 1 to 52
      print #FileHandle, occurances( n )
   next

   close #FileHandle
   place = 0
return

Load:
   input "Enter file to load, w/o extension: "; FileName
   FileName = FileName + ".txt"
   FileHandle = freefile
   open FileName for input as #FileHandle

   for n = 1 to 52
      if( eof( FileHandle ) ) then
         '' [ ...Handle File Format Error... ]
         exit for
      end if
      input #FileHandle, occurances( n )
   next

   close #FileHandle
   place = 0
return
stylin:
Reply


Messages In This Thread
Who here is VERY good at troubleshooting QB programs? - by Anonymous - 10-13-2005, 09:44 AM
Who here is VERY good at troubleshooting QB programs? - by Anonymous - 11-02-2005, 08:42 AM
Who here is VERY good at troubleshooting QB programs? - by stylin - 11-15-2005, 04:17 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)