Drop lowest value from Array and Resize array - VB 2003


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Drop lowest value from Array and Resize array - VB 2003

Hybrid View

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

    Drop lowest value from Array and Resize array - VB 2003

    Hey Everyone!
    My goal is to to reaverage the grades after the lowest has been dropped. I am working with a five element array. I would like to find the lowest value in the array and remove it from the array then resize the array with the elements that remain.
    Since I have sorted the array, I know that I would like to remove the first element in the array since it is the lowest. Below is the code that I have tried but cannot get it to work.

    Thanks for your help!
    Julian

    Sub theArray()
    For i As Integer = 1 To 5
    Console.WriteLine("Enter grade: " & i)
    grades(i) = Console.ReadLine
    sum = grades(i) + sum
    Next
    Array.Sort(grades)
    average = sum / UBound(grades)
    End Sub
    ' i was using this code to replace the first element with nothing
    'then reaverage the grade with only 4 grades instead of five

    Sub DropLowest()
    grades(1) = Nothing
    newAverage = sum / UBound(grades) - 1
    End Sub

  2. #2
    Join Date
    Dec 2004
    Posts
    163
    Julian,

    Is this a homework assignment?

    Kerry Moorman

  3. #3
    Join Date
    Nov 2006
    Posts
    4
    This looks like something I did when I was learning to program! ;-)

    What are you getting for the value @ DropLowest()?

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Why not simply subtract the value of the lowest grade from sum, then divide sum / (UBound(grades) - 1) ?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Aug 2006
    Location
    Albuquerque
    Posts
    32
    Thanks for the replies. Yes it is for an assignment for one of my classes. It was added in to the assignment, if we wanted to do it. The value i get from the dropLowest() is not what i get when i manually add the 4 grades and divide by 4.


    Thanks Phil I will try that approach!!

Similar Threads

  1. redim help !!!
    By angelito in forum VB Classic
    Replies: 1
    Last Post: 11-21-2005, 06:16 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