Results 1 to 3 of 3

Thread: How do I get a min and max value from a file

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2018
    Posts
    6

    How do I get a min and max value from a file

    The task at hand is to read in a file with a list of test scores and names and produce the min and max values in separate labels from that file. The name associated with the min and max scores must also be produced

    The file is as follows:
    Ann 45
    Betty 55
    Carl 75
    David 82
    Erin 77
    Frank 95
    George 92
    Harry 85
    Ian 87
    John 74
    Karen 65
    Larry 86
    Mary 88
    Nancy 90
    Olive 93
    Peter 68
    Quin 62
    Randy 76
    Sarah 78
    Thom 80

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: How do I get a min and max value from a file

    There's no getting around it, just because it's a file. You can't just go to the file and get the information in any fashion that is even vaguely efficient.

    Just read the whole file into memory, using something like ReadAllLines. You can then split each line on space to get an array of strings holding the names in the first element and the scores in the second element. Those scores will be strings, though, so comparing them would be bad, since < and > are defined for strings...they just won't do what you want. Therefore, you have to turn the strings into numbers to do the comparison.

    There are many ways to accomplish all of those steps. The key is that you have to read the whole file into memory, first.
    My usual boring signature: Nothing

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,836

    Re: How do I get a min and max value from a file

    Hmmm...What if two people have the same min or max score? How are you going to handle that?
    Please remember next time...elections matter!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width