Hi,
I've been working on this project I'm doing and its killing me because I can't figure why my array\formula's don't want to get along.
Here is the general overview of what the project requires:
Here the project:
Operation
• The user enters a score and clicks the Add button or presses the Enter key.
• The application calculates and displays the score total, score count, and average score.
• If the user clicks the Display scores button, the application sorts the scores and displays them in a message box.
• If the user clicks the Clear scores button, the application removes all the scores and clears the score, score total, score count, and average controls.
Specifications
• This application should be able to handle at least 20 scores.
• This application should check the number entered by the user to make sure it is a valid integer from 0 to 100.
So far the code I have is below:
private void btadd_Click(object sender, EventArgs e)
{
try
{
if (txtscore.Text == "")
{
MessageBox.Show("Score is a required field.", "Entry Error");
}
else
{
int score = Convert.ToInt32(txtscore.Text);
if (score >= 0 && score <= 100)
{
int sumav = 0;
foreach (int avgscore in scoreTotalArray)
sumav += avgscore;
int avg = sumav / scoreTotalArray.Length;
txtscoretotal.Text = score.ToString();
//txtscorecount.Text = arraycount.ToString();
txtaverage.Text = avg.ToString("d");
//add scores to array (and update index)
scoreTotalArray[scoresIndex] = score;
scoresIndex++;
//add scores to list
scoreTotalList.Add(score);
}
else
{
MessageBox.Show("Score must be greater than 0 and less than 100.", "Entry Error");
}
}
}
catch (FormatException)
{
MessageBox.Show("Please enter a valid number for the Score.", "Entry Error");
}
catch (IndexOutOfRangeException)
{
MessageBox.Show(
"The index is out of range. Please exit the application",
"Entry Error");
}
txtscore.Focus();
}
If anyone can help figure what I'm doing wrong or maybe point me correct direction, my book hasn't help worth crap other than giving me a vague basic idea of what I need.
Thanks in advance.