I'm working on a project and have to figure out how to sort data in a file and display it by first name and age (separately, so there are 2 lists of data). I was thinking about just typing out the data into an array, but apparently the array has to pull the data from the file and then display it. It's kind of hard to explain, so here is an example:
If the data in the file is:
Bob Smith
10
Sarah
8
Mike
12
Scott Brown
14
I would have to display it so the output looks more like this:
Sorted by Age:
Scott Brown 14
Mike 12
Bob Smith 10
Sarah 8Sorted by name:
Bob Smith 10
Mike 12
Sarah 8
Scott Brown 14
I think I have a pretty good understanding of how to write the code to sort it if it was hard coded (which I'm not allowed to hard code it unfortunately), but I'm confused how I would pull the data from the file and use that to sort it out and then display it. I started writing out a do while loop that consists of a for loop and an if statement to sort the names, but the big question is how to use the data from THAT file and display it.
Sorry if it sounds confusing, I'm so lost on this!