Hi i am writing a program that will read a sales.txt file and output the top 2 items sold and their gross sales. unfortunately i can only get the program to output the 2 top sellers but not sure how to get their gross sales displayed also, my output should look like this :
The top selling product is Elec_Drill with total sales of $6031.08
The second top selling product is Hammer with total sales of $4800.95
this is the file
1002 Hammer 23.65 203
1024 Nails 6.95 400
1276 Screwdriver 13.95 251
1385 Elec_Drill 45.69 132
1462 Air_Filter 7.95 500
I don't understand your problem. You've already did this calculation once (see line 39) so now all you should need is to print out that calculation in your print statement.
Also do you realize that one of the benefits of using a structure is that you can "swap" an entire structure at a time, no need to "swap" all the individual elements?
Also using eof() to control the input loop is usually wrong. You should be using the actual file read to control the loop, also since you're using dangerous raw arrays you need to insure you never exceed the array limits. Also beware of subtraction in your array index, you need to insure you don't try to access the array out of bounds. This could happen if your file read fails to read any information.