I'm trying to write a code that will compare a value from each line of an input, and rank the top two based on that value (in this case their weekly sales). But I can't think of a way to do this as the number of input lines won't be consistent (So if/elseif for each individual line would not work)
Here's the input (the employee's name, their hours worked, their weekly sales):
John,40,813
Phil,40,722
Jessica,40,959
Yugo,20,399
So what I want the output to say is:
First: Jessica, 959
Second: John, 813
This is my code so far, it's just the basic skeleton that will read in all the data. If you guys have any hints at all I would love to hear them!
1. Open the file
2. Read in the values (name, sales) line by line and store them in an array(s) or vector - a while loop
3. Close the file
4. Sort the data - you can design your own sort routine or use the library sort functions (STL algorithm)
5. Read off the relevant two
Use the tutorials on this website for guidance on the various components in the pseudocode. :)
Thank you for the response kemort, but I should have mentioned I cannot use any arrays, vectors, or the like. The sorting has to be done line by line, which is where I'm having so much trouble coming up with a code