Desperately in need of help

Icon

afgncaap5aolcom
Hello.  I'm working with Icon in a project that is being managed by a
professor.  Now, lately the professor has started to just dodge
questions whenever I ask him for any help whatsoever.  Some other
definite communication issues are arising as well, and it's becoming
very difficult to proceed.

Anyway, I'm working towards creating a very simple, basic program that
will create data tables.  Each cell of the table is named after a
letter of the alphabet, and each cell contains the number of times
that this letter has been encountered in the input.  After this stage,
a random number generator is used to find a number between 0 and 1,
and each of the numbers in the cells are to be divided by the sum
total of all of the cells.  The program will then select a letter of
the alphabet based on all of this.

Now, my prof keeps telling me that there's an error in the code but is
absolutely refusing to tell me where the error is, what the error is
doing, and how I can go about fixing it.  Can someone help me? 
Included is a copy of the material that I'm working with.

procedure main()
	&random :=0 #randomizes the timer
	primary := table(0)  #Creates a table with all values equal to zero
	
	test := string(&lcase)  # Creates a string based on all lower-case
letters

	every primary[!test] +:=1  #Goes through every letter in the alphabet
and increments it by one
	sum := 0  # creates a value of sum equal to zero
	every x := !&lcase do
		sum +:= primary[x]
	
	cumcounts := 0
	cumprob := table(0.0000)
	every x:=!&lcase do{
		cumcounts +:= primary[x]
		cumprob[x]:=(cumcounts*1.0000)/(sum	*1.0000)
	}
	
	
	randnum := ?0
	every x := !&alphabet do {
		if randnum <= primary[x] then { 
			letter := x
		}
	}

	write(x)
			
end                                            
Steve
...

Have you tried compiling the code yet?  There's definitely
a syntax error - there is no keyword &alphabet.  I suspect
you mean &lcase again.  This is a bit worrisome, as it means
you haven't tried running the program yourself yet...

There are also some logic flaws, from what I understand of
the problem.  For example:

As it's written now, the entire program can be rewritten as:

   procedure main()
       write("z")
   end

which probably isn't what you want!   (My guess is that this
is a work in progress, where you'll be adding more to the
program as you get this part running.)

Finally, the statement:

    &random := 0

probably isn't doing what you want.  That does not
randomize a timer.  In fact, 0 is the initial value
of &random, so the above line isn't really doing anything.

If you want a different sequence of random numbers generated
each time you run the program, you'll have to assign a
unique (different) seed to &random each time you run the
program.