First off: and most important
Fatsbear please read the first announcement in this forum about code tags. Then use them.
Second: The problem is the association between calories and the food name.
You will find other posts, by your classmates I suspect, who have solved the problem by sorting on calories and then making the same moves on the foodname. This is an ugly solution. Especially, if you then have more information to associate, e.g. the price, the age .
Your best solution is to associate the food name with the calories in a class. Create an array/vector of you food class and sort the group as a whole.
The idea of a 2d array is simply not the way forward. It doesn't represent the underlying problem structure and in very difficult to extend.
Overload the operator< or use a comparison function and use the
standard sort algorithm, or write you own.
Finally, bubble sort is one of the worst sorts available and should never be used (except some very rare cases). It is simply too slow.
Despite JLopeman's careful minimization of the loop passes, on a long random list it is still horrifically slow.
Anyway, you should write some code and post that for comment/problem solving.
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138