I have a calculator that is supposed to take in scores, compute score total,score count,and score average. I am also to create a list that will store all the scores that have been entered and display them in msgbox which I have already done and have working. My problem is that I cant figure out how to use the ".count" property of a list. I attempted it and when I add in a score it starts at zero instead of one. Also if anyone would be able to help me on how I might get the score total and average to work as well. Thanks
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ScoreCalculator
{
public partial class frmScoreCalculator : Form
{
public frmScoreCalculator()
{
InitializeComponent();
}
List<int> intScoresList = new List<int>();
private void btnAdd_Click(object sender, EventArgs e)
{
int intScore = 0;
Int32.TryParse(txtScore.Text,out intScore);
//int intScoreCount = 0;
txtScoreCount.Text = intScoresList.Count.ToString();
intScoresList.Add(intScore);
txtScore.Focus();
txtScore.SelectAll();
}
private void btnDisplayScores_Click(object sender, EventArgs e)
{
intScoresList.Sort();
string DisplayScore = "";
foreach (int score in intScoresList)
{
DisplayScore += score.ToString() + "\n";
}
MessageBox.Show(DisplayScore, "Sorted Scores");
txtScore.Focus();
}
private void btnClearScores_Click(object sender, EventArgs e)
{
intScoresList.Clear();
this.txtScore.Clear();
this.txtScoreCount.Clear();
this.txtAverage.Clear();
this.txtScoreTotal.Clear();
//this.intScoreCount = 0;
//this.intScoreTotal = 0;
txtScore.Focus();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}