Objective: User enters a score then clicks Add button. Everytime Add button is clicked a Score is added to previous score to display total, averaged,counter.
Issue: I enter first scores then click add. The first score displays but the second score overwrites the first. It is not accumulating.
I believe I am missing something fundamental or should I create a seperate method to keep the running total and count. Here is a snippet of what I have
private void AddScore_Click(object sender, EventArgs e)
{
decimal Score=0m,
Average=0m,
ScoreTotal=0m;
List<decimal> myScoreList = new List<decimal>();
myScoreList.Add(Convert.ToDecimal(Score.Text));
//myScoreList.Add(5);
//myScoreList.Add(6);
//myScoreList.Add(7);
for (int i = 0; i < myScoreList.Count; i++)
{
Score = myScoreList [i];
ScoreTotal += Score;
Average = ScoreTotal / myScoreList.Count;
}
this.lblDisplayScrTotal.Text = ScoreTotal.ToString();
this.lblDisplayScrCount.Text = ScoreList.Count.ToString();
this.lblDisplayAverage.Text = Average.ToString();
}
} }