If their is anyone who can help me I'm having a problem in my score calculator in which it's suppose to calculate the user input of as many numbers they wish giving the score total, score count, and score average but when the user enters the numbers they wish to add it also adds the score total how can I stop it from adding the score total? PLEASE HELP!
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 ScoreCalculatorProj
{
public partial class frmScoreCalculator : Form
{
// Creates the list where user can enter the score as many times as they please
List<decimal> scores = new List<decimal>();
decimal scoreaverage = 0;
decimal scoretotal = 0;
decimal scorestandarddev = 0;
decimal score;
public frmScoreCalculator()
{
InitializeComponent();
}
// Pulls out the about form when user clicks the about button
private void btnAbout_Click(object sender, EventArgs e)
{
frmAbout form = new frmAbout();
form.Show();
}
// Button so user input could be accepted for addition process
// Calculates the addition of the scores entered by the user
private void btnAdd_Click(object sender, EventArgs e)
{
score = decimal.Parse(txtScore.Text);
scores.Add(score);
for (int i = 0; i < scores.Count; i++)
{
// Calculates the score user input to receive score total
scoretotal += scores[i];
}
// Calculates the score average of the users score input
scoreaverage = scoretotal / scores.Count;
// Displays the scoreaverage, scorecount, score total, as well as recieves users score input
txtScoreaverage.Text = scoreaverage.ToString();
txtScorecount.Text = scores.Count.ToString();
txtScoretotal.Text = scoretotal.ToString();
txtScore.Text = "";
txtScore.Focus();
}
// Button to display the user score input in a sorted order
private void btnDisplayScores_Click(object sender, EventArgs e)
{
string numbersString = "";
foreach (decimal score in scores)
{
numbersString += score + "\n";
}
MessageBox.Show(numbersString, "Sorted Scores");
}
// Button to clear the textbox, output labels, items from the list box, and elements of the list
private void btnClearScores_Click(object sender, EventArgs e)
{
txtScore.Text = "";
txtScore.Focus();
scores.Clear();
scoreaverage = 0;
scoretotal = 0;
scorestandarddev = 0;
score = 0;
txtScoreaverage.Text = "";
txtScorecount.Text = "";
txtScoretotal.Text = "";
txtScorestandarddev.Text = "";
}
// Button to exit program
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}