AllExperts > Qbasic, Quickbasic 
Search      
Qbasic, Quickbasic
Volunteer
Answers to thousands of questions
 Home · More Qbasic, Quickbasic Questions · Answer Library  · Encyclopedia ·
More Qbasic, Quickbasic Answers
Question Library

Ask a question about Qbasic, Quickbasic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Alex 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++

 
   

You are here:  Experts > Computing/Technology > Basic > Qbasic, Quickbasic > Finding modes with Qbasic

Qbasic, Quickbasic - Finding modes with Qbasic


Expert: Alex Barry - 3/13/2009

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

Hope that helps,
-Alex

The mode should be the last

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.