Get Average of Array - Visual Basic 2003


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Get Average of Array - Visual Basic 2003

  1. #1
    Join Date
    Aug 2006
    Location
    Albuquerque
    Posts
    32

    Get Average of Array - Visual Basic 2003

    Hey Everyone!
    I am writing a simple program that calculates the average grades from user input.

    I need help with the following:
    1) I have been getting the average of an array by doing the following Sub calcAverage()
    average = grades(1) + grades(2) + grades(3) + grades(4) + grades(5) / 5
    End Sub

    2)Is there a way to combine this with the function to add grades to the array and use the lower and upper bounds to determine what the denominator will be?
    Here is the code for the array:
    Sub sortarray()
    Array.Sort(grades)
    For i As Integer = 1 To 5
    sortedArray(i) = (grades(i))
    Next
    End Sub

    THANKS for looking this over!

  2. #2
    Join Date
    Aug 2006
    Location
    Albuquerque
    Posts
    32
    sorry it seems like every time i write it out, i am able to figure it out. of course if there is an alternative way of doing this please let me know.This is what I came up with.

    Sub sortarray()
    Array.Sort(grades)
    For i As Integer = 1 To 5
    sortedArray(i) = (grades(i))
    sum = sortedArray(i) + sum
    count = count + 1
    average = sum / count

    Next
    End Sub

Similar Threads

  1. Replies: 0
    Last Post: 05-20-2003, 07:06 AM
  2. Book Reviews: "Programming the Web with Visual Basic .NET"
    By Constance J. Petersen in forum dotnet.announcements
    Replies: 0
    Last Post: 11-22-2002, 10:40 AM
  3. New Apress book by DevX section leader -- Bargain Error Price on BarnesAndNoble.com
    By Constance J. Petersen in forum dotnet.announcements
    Replies: 0
    Last Post: 07-26-2002, 03:32 PM
  4. yag's status report - April 11, 2002
    By Yair Alan Griver [MS] in forum vb.announcements
    Replies: 0
    Last Post: 04-11-2002, 08:33 PM
  5. ActiveX DLL created with MS Visual Basic 6.0
    By Pierluigi in forum VB Classic
    Replies: 0
    Last Post: 07-25-2000, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center