I did a previous program takes scores from the user and computes the total of the scores, score count, and score average.Now I am supposed to add an array that will store the scores the user inputs and display them in a message box
more detailed instructions below:
- Delete the class-level score total variable and replace it with a class-level array that can hold up to 20
scores. - Modify the Click event handler for the Add button so it adds the score that’s entered by the user to the
next element in the array. To do that, you can use the class-level score count variable to refer to the
element. - Move the Clear Scores button as shown above. Then, modify the Click event handler for this button
so it removes any scores that have been added to the array. The easiest way to do that is to create a
new array and assign it to the array variable (e.g., scores = new int[20];). - Add a Display Scores button that sorts the scores in the array, displays the scores in a dialog box, and
moves the focus to the Score text box. Be sure that only the elements that contain scores are
displayed.
heres what I have so far, the main thing I need help on is just getting the array to work. Then I can figure out how to get the score total and average to work. Alos the messagebox should show the scores vertically using (/n) and not horizontal like I think I have it now
public partial class frmScoreCalculator : Form
{
public frmScoreCalculator()
{
InitializeComponent();
}
int[] intScoreTotalsArray = new int[20];
int intScoreCount = 0;
/// <summary>
/// this event calculates the score total, score count, and average
/// when the user clicks the Add buttont to add more scores to the form. Also gives focus to txtScore.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAdd_Click(object sender, EventArgs e)
{
int intScore = 0;
Int32.TryParse(txtScore.Text,out intScore);
intScoreCount++;
txtScoreTotal.ToString();
txtScoreCount.Text = intScoreCount.ToString();
txtScore.Focus();
txtScore.SelectAll();
}
/// <summary>
/// This event clears all the textboxes amd sets the stored values
/// back to zero when user clicks the clear button. Also gives focus to txtScore.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnClearScores_Click(object sender, EventArgs e)
{
this.txtScore.Clear();
this.txtScoreCount.Clear();
this.txtAverage.Clear();
this.txtScoreTotal.Clear();
this.intScoreCount = 0;
this.intScoreTotalsArray = new int[20];
txtScore.Focus();
}
/// <summary>
/// This event closes the form when the user clicks the Exit button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDisplayScores_Click(object sender, EventArgs e)
{
Array.Sort(intScoreTotalsArray);
string intScoreTotalsArray = "";
for (int i = 0; i < intScoreTotalsArray.Length; i++)
numbersString += intScoreTotalsArray[i] + " ";
MessageBox.Show(intScoreTotalsArray, "Sorted Scores");