using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; /* * * Name: Joseph Schuman * Date: 9/22/2015 * Folder: Chap-04-2-SC * Description: Takes score and calculates score total, score count, and score average. * * */ namespace Chapter4_2ScoreCalculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } int scoreTotal = 0; int scoreCount = 0; private void Form1_Load(object sender, EventArgs e) { } private void btnExit_Click(object sender, EventArgs e) { //Close the form. this.Close(); } private void btnClrScores_Click(object sender, EventArgs e) { //Set variables to 0, clear numbers from text boxes, and set focus to Score text box. scoreCount = 0; scoreTotal = 0; txtAverage.Text = ""; txtScore.Text = ""; txtScoreCount.Text = ""; txtScoreTotal.Text = ""; txtScore.Focus(); } private void btnAdd_Click(object sender, EventArgs e) { //Add score values. int score = Convert.ToInt32(txtScore.Text); scoreTotal += score; //Increase Score Count. scoreCount++; //Calculate average grade number. int avg = scoreTotal / scoreCount; //Display results in text boxes. txtScoreTotal.Text = scoreTotal.ToString("n0"); txtScoreCount.Text = scoreCount.ToString("n0"); txtAverage.Text = avg.ToString("n0"); } } }