Student needs help

  • Thread starter Thread starter drg
  • Start date Start date
D

drg

My assignment is to have a user add scores to a listbox then write a
method to find the highest and lowest score in the list.

I am able to get and display the first index or the last index, or even
count the number of indexes, via foreach, if, while and for loops. I
can't seem to check each individual index against a common int to find
the highest or lowest.

I am using Visual C# Express edition 2005 and creating a Windows
Application.

I'm not asking for you to do my assignment I just need a hint, a clue --
something.

DRG
 
Is it the high and low score you are not able to get?

If so get a list of scores on a piece of paper and work out how You would
decide which is the lowest and highest number.... do it without thinking
about code, but work from the top of the list to the bottom.

come back if this is not enough of a hint....

Richard
 
drg said:
My assignment is to have a user add scores to a listbox then write a
method to find the highest and lowest score in the list.

I am able to get and display the first index or the last index, or even
count the number of indexes, via foreach, if, while and for loops. I
can't seem to check each individual index against a common int to find the
highest or lowest.

I am using Visual C# Express edition 2005 and creating a Windows
Application.

I'm not asking for you to do my assignment I just need a hint, a clue --
something.


I do this sort of thing by having a variable called "CurrentHighScore" or
something.
Set to zero to start off
Loop through your results, and if a score is higher than the current high
score, update the current high score.
At the end, the high score is the... er, high score.
 
Ya, use Jame's approach.
Start with two variables High, Low
Set High to be something like -1
and set Low to a number higher then any number you would have to deal
with.
Then for high, if a number is higher than High, make it the new high
number, same logic for low number.
 
rhaazy said:
Ya, use Jame's approach.
Start with two variables High, Low
Set High to be something like -1
and set Low to a number higher then any number you would have to deal
with.
Then for high, if a number is higher than High, make it the new high
number, same logic for low number.

There are two constants that I would use instead of some arbitrary starting
numbers...

If you are using an 'int' value, I would use int.MaxValue for the starting
LOW number and int.MinValue for the starting HIGH number.

HTH,
Mythran
 
Thanks for the help everyone. It seems that the line of code I was
missing was:

firstScore = int.Parse(lstScores.Items[scoreIndex].ToString());

without that I was not able to advance to the next index.

thanks again and as Arnold would say "I'll be back",

drg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top