Computer Science Canada Help with algorithm

Author:  tum_twish [ Mon Jun 23, 2003 7:46 pm ]
Post subject:  Help with algorithm

Does anyone know what is wrong with my NBA standings algorithm?
-it's supposed to put the 2 division winners at the top of the conference
-the rest of the teams are supposed to be ranked by best percentage
 code: var homeTeamName, roadTeamName : string var homeTeamScore, roadTeamScore : int var homeWins, roadWins, homeLoss, roadLoss : int var finalScoreButton : int var textField : array 1 .. 4 of int var textFieldLabel : array 1 .. 4 of int var labelText : array 1 .. 4 of string := init ("Home Team", "Road Team",     "Score", "Score") var fp : int class Team     import fp     export Percent, Get_Info, Name, Add_Win, Add_Loss, Put, Division,         Conference, Wins, Loss     var division, conference, name : string     var wins, loss, percent : real     procedure Percentage         if wins + loss > 0 then             percent := wins / (wins + loss)         else             percent := 0.5         end if     end Percentage     function Get_Line : string         var line : string         get : fp, line : *         get : fp, skip         result line     end Get_Line     procedure Get_Info (filename : string)         open : fp, filename, get         name := Get_Line         division := Get_Line         conference := Get_Line         wins := strreal (Get_Line)         loss := strreal (Get_Line)         close : fp         Percentage     end Get_Info     procedure Put (filename : string)         open : fp, filename, put         put : fp, name         put : fp, division         put : fp, conference         put : fp, wins         put : fp, loss         close : fp     end Put     function Name : string         result name     end Name     function Division : string         result division     end Division     procedure Add_Win         wins := wins + 1         Percentage     end Add_Win     procedure Add_Loss         loss := loss + 1         Percentage     end Add_Loss     function Percent : real         result percent     end Percent     function Conference : string         result conference     end Conference     function Wins : real         result wins     end Wins     function Loss : real         result loss     end Loss end Team var eastStandings : array 1 .. 15 of int var westStandings : array 1 .. 15 of int var team : array 1 .. 29 of ^Team var filename : array 1 .. 29 of string := init ("njn.txt", "phi.txt",     "bos.txt", "orl.txt", "wsh.txt", "nyk.txt", "mia.txt", "det.txt",     "ind.txt", "noh.txt", "mil.txt", "atl.txt", "chi.txt", "tor.txt",     "cle.txt", "sas.txt", "dal.txt", "min.txt", "uta.txt", "hou.txt",     "mem.txt", "den.txt", "sac.txt", "lal.txt", "por.txt", "pho.txt",     "sea.txt", "gsw.txt", "lac.txt") var orderedArray : array 1 .. 29 of int var d1, d2 : int procedure Nothing (text : string) end Nothing procedure Swap (var a, b : int)     var x : int     x := a     a := b     b := x end Swap procedure Sort     var largest : int := 1     for i : 1 .. 29         orderedArray (i) := i     end for     for pass : 1 .. 28         for element : pass .. 29             if team (orderedArray (element)) -> Percent >                     team (orderedArray (largest)) -> Percent then                 largest := element             end if         end for         Swap (orderedArray (pass), orderedArray (largest))         largest := pass     end for end Sort procedure Division (div1, div2 : string, var d1, d2 : int)     var i : int := 1     loop         exit when team (orderedArray (i)) -> Division = div1         i := i + 1     end loop     d1 := orderedArray (i)     i := 1     loop         exit when team (orderedArray (i)) -> Division = div2         i := i + 1     end loop     d2 := orderedArray (i) end Division procedure Eastern_Conference     var i : int := 1     var x : int := 3     loop         exit when i > 29         if team (orderedArray (i)) -> Conference = "Eastern" then             if orderedArray (i) not= d1 and orderedArray (i) not= d2                     then                 eastStandings (x) := orderedArray (i)                 x := x + 1             end if         end if         if i not= 29 and orderedArray (i + 1) not= d1 and orderedArray (i +                 1) not= d2 then             i := i + 1         else             i := i + 2         end if     end loop end Eastern_Conference procedure Western_Conference     var i : int := 1     var x : int := 3     loop         exit when i > 29         if team (orderedArray (i)) -> Conference = "Western" then             if orderedArray (i) not= d1 and orderedArray (i) not= d2                     then                 westStandings (x) := orderedArray (i)                 x := x + 1             end if         end if         if i not= 29 and orderedArray (i + 1) not= d1 and orderedArray (i +                 1) not= d2 then             i := i + 1         else             i := i + 2         end if     end loop end Western_Conference procedure Standings     var i : int := 1     var x : int     Sort     Division ("Atlantic", "Central", d1, d2)     if team (d1) -> Percent > team (d2) -> Percent then         eastStandings (1) := d1         eastStandings (2) := d2     else         eastStandings (1) := d2         eastStandings (2) := d1     end if     Eastern_Conference     put         "        Eastern Conference                         Western Conference"     put         "Rank   Name             W   L  %      Rank    Name                W   L   %"     for a : 1 .. 15         locate (a + 3, 2)         put a         locate (a + 3, 5)         put team (eastStandings (a)) -> Name         locate (a + 3, 25)         put team (eastStandings (a)) -> Wins, "  ", team (eastStandings (a))             -> Loss, "  ", team (eastStandings (a)) -> Percent     end for     Division ("Midwest", "Pacific", d1, d2)     if team (d1) -> Percent > team (d2) -> Percent then         westStandings (1) := d1         westStandings (2) := d2     else         westStandings (1) := d2         westStandings (2) := d1     end if     Western_Conference     for a : 1 .. 14         locate (a + 3, 40)         put a         locate (a + 3, 43)         put team (westStandings (a)) -> Name         locate (a + 3, 67)         put team (westStandings (a)) -> Wins, "  ", team (westStandings (a))             -> Loss, "  ", team (westStandings (a)) -> Percent     end for end Standings for i : 1 .. 29     new team (i)     team (i) -> Get_Info (filename (i)) end for Standings

 Author: Andy [ Mon Jun 23, 2003 8:25 pm ] Post subject: you should give us an example textfile so we dun have to figure your entire code to fix a single problem and tell us what's the exat problem, no one wants to sit there for 30 min trying to debug ur entire code

 :