![]() |
Forum Index : Microcontroller and PC projects : Highest value in an array
Author | Message | ||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
I can't seem to see the forest fore the trees moment... I have a simple 10 element array Score(1) thru Score(10). Each element has a different number in it. I am trying to do two things, first find which element has the highest number in it and then which elements are the same as the highest number. I have tried this... For Zz = 1 to 9 If Score(Zz) > Score(Zz + 1) Then WinTemp = Zz Else WinTemp = Zz + 1 End If Next Zz Print "High Score = ";Score(WinTemp) Big fat fail. Any ideas on finding the high score and then which elements are tied with the high score? |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Ok played a bit more... found highest value, now to find ties... need to untie my brain a bit. Dim Score(10) = (140, 13, 99, 2, 22, 210, 37, 20, 120, 40) Max = 0 For Zz = 1 to 10 If Score(Zz) > Max Then Max = Score(Zz) MaxLoc = Zz End If Next Zz Print "max = ";Max;" in location ";MaxLoc |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
This is one way I had to put an extra value in the array initialization line to fill location Score(0) That would depend on what OPTION BASE you have set. I often find that doing a 'sort' on the array lets you pull the various rankings out easily. It depends on what the goal is. > RUN max = 210 In location 5 In location 10 Total sharing max = 2 > Jim VK7JH MMedit |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Excellent, thank you TassyJim! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |