Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# Score Calculator I'm having difficulty getting the code to run. Consistantly asking for Items to be defined. Task: C-Sharp University is in need of

C# Score Calculator

I'm having difficulty getting the code to run. Consistantly asking for "Items" to be defined.

Task:

C-Sharp University is in need of a form that accepts one or more scores from the user. Each time a score is added, the score total, score count, and average score are calculated and displayed.

1. Start Visual Studio.

2. Click the Create Project hyperlink or use the File-New Project menu option.

3. In the New Project dialog box type a name for the projectname the project Lab4_8-SectionTime-YourLastName-YourFirstName.

4. Change the forms File Name property from Form1.vb to a new name Lab4.cs

5. Change the title of the form as shown above (C-Sharp Score Calculator).

6. Add labels, text boxes, and buttons to the default form and set the properties of the form and its controls so they appear as shown above. When the user presses the Enter key, the Click event of the Add button should fire. When the user presses the Esc key, the Click event of the Exit button should fire.

7. Declare two class variables to store the score total and the score count and set them equal to 0.

8. Create an event handler for the Click event of the Add button. This event handler should get the score the user enters, calculate and display the score total, score count, and average score, and move the focus to the Score text box. It should provide for integer entries, but you can assume that the user will enter valid integer values. Convert the score textbox into an integer Accumulate the score and assign it to the score total class variable Accumulate the count Create a variable to store the average and calculate the average by dividing total count by total score. Display the score total, count total, and average back to the correct textboxes on the form. Set the focus back to the score textbox.

9. Create an event handler for the Click event of the Clear Scores button. This event handler should set the two class variables to zero, clear the text boxes on the form, and move the focus to the Score text box.

10. Create an event handler for the Click event of the Exit button that closes the form.

11. Test the application to be sure it works correctly. (enter 50, 60, and 90).

Code I have so far:

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 Lab4_8_200_Cooper_Clayton { public partial class Lab4 : Form { Listscores = new List(); double average = 0; double scoreTotal = 0; double score; public Lab4() { InitializeComponent(); }

private void Lab4_Load(object sender, EventArgs e) { }

private void btnAdd_Click(object sender, EventArgs e) { score = double.Parse(txtScore.Text); scores.Add(score); txtScore.Items.Add(score);

for (int i=0; i

average = scoreTotal / scores.Count; lblAverage.Text = average.ToString(); lblScoreCount.Text = scores.Count.ToString(); lblScoreTotal.Text = scoreTotal.ToString(); txtScore.Text = ""; txtScore.Focus();

txtScore.Sorted = true;

}

private void btnClearScores_Click(object sender, EventArgs e) { txtScore.Clear(); txtScore.Text = ""; txtScore.Focus(); scores.Clear(); average = 0; scoreTotal = 0; score = 0; lblAverage.Text = ""; lblScoreCount.Text = ""; lblScoreTotal.Text = ""; }

private void btnExit_Click(object sender, EventArgs e) { this.Close(); }

} }

This is the Form I have now

image text in transcribed

Eile Edit View Project Build Debug Team Format Debug Any CPU Lab4.cs Lab4.cs [Design] C-Sharp Score Calculator Score 8e2 Score total: Score count: Average: Clear Scores Exit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions