Testing For Highest Number in an array

  • Thread starter Thread starter WStoreyII
  • Start date Start date
W

WStoreyII

i have a lab due for my computer logic class here is the assignment

you are given a hundred cards all greater than or = to one
write an algorithm that will find the highest card.

i have started by creating a form with a text box a label an a button
i have the users inputing the numbers in a text box seperated by commas and
then using the split method
to assign each number to a array called strcards

my question though is that i have tried all day to figure out a code to run
throuhg and test each number compared to others but have not got anywhere.

How should i go about writing this code?

WStoreyII

Thanks in advance
 
* "WStoreyII said:
you are given a hundred cards all greater than or = to one
write an algorithm that will find the highest card.

i have started by creating a form with a text box a label an a button
i have the users inputing the numbers in a text box seperated by commas and
then using the split method
to assign each number to a array called strcards

my question though is that i have tried all day to figure out a code to run
throuhg and test each number compared to others but have not got anywhere.

<http://www.google.de/[email protected]>
 
Hi,

Dim arInt(20) As Integer

For i As Integer = 0 To 20

arInt(i) = CInt(2000 * Rnd(2000))

Next

Dim intMax As Integer = arInt(0)

For i As Integer = 1 To 20

If arInt(i) > intMax Then intMax = arInt(i)

Next

MessageBox.Show(intMax.ToString)



Ken
 
WStoreyII said:
i have a lab due for my computer logic class here is the assignment

you are given a hundred cards all greater than or = to one
write an algorithm that will find the highest card.

i have started by creating a form with a text box a label an a button
i have the users inputing the numbers in a text box seperated by commas and
then using the split method
to assign each number to a array called strcards

my question though is that i have tried all day to figure out a code to run
throuhg and test each number compared to others but have not got anywhere.

How should i go about writing this code?

I see others have give you "code" already so I'll pass along a little advice
:-)

Resist the temptation to "start writing" until you have an idea of what you
are going to write. This is a particularly bad problem with UI-centric
tools like VB.Net. You already knew that you could make a form and drag
labels, textboxes and buttons onto it so don't waste your time with that.
It makes it seem like you are "half-way done" when in reality you haven't
begun. Write pseudocode first it gives you a chance to think in conceptual
terms rather than worry about "VB syntax."

Did you need to know the highest card value or the card position of the card
with the highest value? If the card "position" you can't mess with the
cards and since the highest value can be on any of the cards there is no
alternative but to walk through the set of cards. If you just need the
highest value there is an alternative solution... you can sort the array and
grab (depending upon your sort order) the last (or first) element's value.

Tom
 
Why not just plug all your values into Arraylist, call sort and then get
myarr(99)?

hth
Richard
 
Hi WStoryII

When it is a gambling game, than it should be with every deal new.
You can build an index but when you do not it can in my opinion be not more
than.

dim topvalue as integer = 0
dim topindex as integer = 0
For i as integer = 0 to arraylenght - 1
if topvalue > myarray(i) then
topvalue = myarray(i)
topindex = i
next
messagebox.show("It is card: " & topindex.tostring & " with the value: " &
topvalue.tostring)

All logic will fail in my opinion, because there should be in a good
shuffled carddeck no logic.

I hope this helps,

Cor
 
oh i see but no the assingement is just to write and algorithm that would
find teh highest card the max function from the other posts worked very well
 
WStoreyII said:
huh

what ????

WStoreyII
"Richard" <[email protected]> wrote in message

Dim strcards() As Long
Try
strcards = CType(Me.txtValues.Text.Split(";"c), Long())
Catch e As InvalidCastException
MessageBox.Show("Please ensure you enter only numbers into the
textbox")
Exit Sub
End Try

Array.Sort(strcards)
MessageBox.Show(String.Format("Highest value is {0}",
strcards(strcards.Length - 1)))


hth
Richard
 
Back
Top