AboutAlex Barry Expertise I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, c/c++, python, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.
Experience Hobby programming since 2000
I no longer belong to any community programming groups, but do have knowledge of *basic dialects and C/C++
Question Hey i'm a teacher and have been trying to write a program that will be able to
give me information about student's scores, averages, and things like that. I
have have almost the entire thing written with a two dimensional array but i just
cannot figure out how to get the mode of an array. if you could help thatd be
great
Answer Hi, Jason,
If you wanted to get the mode (most common number, yes?), there are a few ways to do it. I prefer the quick and dirty way:
DIM mode(0 TO 100) AS INTEGER
DIM i AS INTEGER
FOR i = LBOUND( scores ) TO UBOUND( scores )
mode( scores( i ) ) = mode( scores( i ) ) + 1
NEXT i
DIM j AS INTEGER
DIM id AS INTEGER
DIM num AS INTEGER
id = -1
num = 0
FOR i = 1 TO 100
IF mode( i ) > num THEN
id = i
num = mod( i )
END IF
NEXT i
PRINT USING "Class score mode: ### (### students)"; id, num