basically i had to write a program where a user enters the amount of countrys taking part in the Olympics and enters there medals. i should then be able to sort the country's out with the best country being the one with the most amount of gold meals. my problem is its not sorting it out and oping someone could help. i also have a problem where i automatically want the program t work out the total by it self and don't know where to put it.
thanks in advance
data Code:
Public Class fmldn Structure Olympicsinfo Dim country As String Dim gold As String Dim silver As String Dim bronze As String Dim total As String End Structure Dim Olympics() As Olympicsinfo Dim N As Integer Private Sub btnenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenter.Click N = InputBox("Enter the number of Countrys") ReDim Olympics(0 To N - 1) For I = 0 To N - 1 Olympics(I).country = InputBox("Enter the Country") Olympics(I).gold = InputBox("Enter the Amount of Gold Medals") Olympics(I).silver = InputBox("Enter the Amount of Silver Medals") Olympics(I).bronze = InputBox("Enter the Amount of Bronze Medals") Olympics(I).total = InputBox("Enter the Total Amount Of Medals") Next End Sub Private Sub Display() DGVolympics.Rows.Clear() For I = 0 To N - 1 dgvolympics.Rows.Add(Olympics(I).country, Olympics(I).gold, Olympics(I).silver, Olympics(I).bronze, Olympics(I).total) Next End Sub Private Sub btnview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnview.Click Call Display() End Sub Private Sub btnsort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsort.Click Dim Swap As Boolean Dim temp As Olympicsinfo 'Perform the Bubble Sort Do Swap = True For I = 0 To N - 2 If Olympics(I).gold > Olympics(I + 1).gold Then Swap = True temp = Olympics(I) Olympics(I) = Olympics(I + 1) Olympics(I + 1) = temp End If Next I N = N - 1 Loop Until (Not (Swap) Or (N = 1)) End Sub End Class





Reply With Quote
