I need a form that accepts scores from the user, displays the total, count, and average of the scores, and displays a dialog box that lists the scores.

Operation

The user enters a score. If the user clicks the Add button or presses the Enter key the application calculates and displays the score total, score count, and average score. Optional: the application clears the score and returns focus to the score textbox.

If the user clicks the Display scores button, the application sorts the scores (lowest to highest) and displays them in a message box.

If the user clicks the Clear scores button, the application removes all the scores and clears the score, score total, score count, and average controls.

If the user clicks the Exit button or presses the Escape key the application closes.

Specifications

This application should check the number entered by the user to make sure it is a valid integer from 0 to 100. If a value is entered outside this range, the score does not count (and should not be included in the score total, score count, or average).

Here are my errors:

Error1  The name 'scoreCount' does not exist in the current context 
Error2  The name 'scoreCount' does not exist in the current context 
Error3  The name 'scoreCount' does not exist in the current context 
Error4  The name 'scoresArray' does not exist in the current context    
Error5  The name 'scoresArray' does not exist in the current context    
Error6  'JonesJAsign8.Form1' does not contain a definition for 'clearScores' and no extension method 'clearScores' accepting a first argument of type 'JonesJAsign8.Form1' could be found (are you missing a using directive or an assembly reference?) 

I'll post what I have as a reply.

Any help is greatly appreciated.
Thanks in advance.

Recommended Answers

All 11 Replies

public Form1()
        {
            InitializeComponent();
        }

        //declare class variables for array and list here

        int totalScores = 0;

        int[] scoreTotalsArray = new int[20];



        //initialize the variable for the list

        List<int> scoreTotalsList = new List<int>();



        private void btnAdd_Click(object sender, EventArgs e)

        {

          try

          {

              if(txtScore.Text == "")

              {

                  MessageBox.Show("Score is a required field.", "Entry Error");

             }

              else

             {

                int score = Convert.ToInt32(txtScore.Text);

                if(score > 0 && score <= 100)

                  {

                    totalScores += score;

                    scoreCount++;

                    decimal average = totalScores / scoreCount;



                    txtScoreTotal.Text = totalScores.ToString();

                    txtScoreCount.Text = scoreCount.ToString();

                    txtAverage.Text = average.ToString("f2");



                    //add score to array (and update index)

                    scoreTotalsArray[totalScores] = totalScores;

                    totalScores++;



                    //add total to list

                    scoreTotalsList.Add(totalScores);

                }

                else

               {

                    MessageBox.Show("Score must be greater than 0 and less than or equal to 100.", "Entry Error");

                }

              }

          }

            catch (FormatException)

          {

                MessageBox.Show("Please enter a valid number for the Score field.", "Entry Error");

            }

            txtScore.Focus();

        }



        private void btnDisplayScores_Click(object sender, EventArgs e)

        {

            Array.Sort(scoresArray);
            string message ="";

            foreach (int score in scoresArray)

            {

                if (score != 0)

                {

                    message += score.ToString() + "\n";

                }

            }

            MessageBox.Show(message, "Sorted Scores");



            scoreTotalsList.Sort();

            message = "";

            foreach (int score in scoreTotalsList)

            {

                message += score.ToString() + "\n";

            }

            MessageBox.Show(message, "Scores - List");

        }










        private void btnExit_Click(object sender, EventArgs e)

        {

            this.Close();

        }

        private void clearBtn_Click(object sender, EventArgs e)
        {
            this.clearScores();
        }






     }


        }

This is what I have

You never initilise scoreCount so any instances of
scoreCount++;
will fail. You need to include
int scoreCount = 0;
at the start (as you have done for totalScores.
And scoresArray is declared as scoreTotalsArray so you just have the variable name wrong on line 106.

So are you asking for code that makes that form?

yes or can you help me correct the errors I have listed

Well I got it all fixed and working except I can't post any code. The </> Code button doesn't do anything and I can't post it. So, any help on how the heck one posts code would be appreciated LOL

The button was messing up for me as well. If its not asking too much you could email it to me. My email is jonesjayjuan@yahoo.com.

Thanks for even taking time out to help

sent

Thank you so MUCH! I need help with one last thing! The clear button you coded didn't work. I need the clear button to clear all the textboxes which I've already coded but I also need it to clear the counter. Any suggestions?

Whoops. I wrote the function call and didn't code it
inside of it LOL
Just put this in it
That should clear all globals and reset the arrays

this.txtScore.Clear();
this.txtScoreCount.Clear();
this.txtAverage.Clear();
this.txtScoreTotal.Clear();
this.scoreCount = 0;
this.scoreTotalsArray = null;
this.scoreTotalsArray = new int[20];
this.scoreTotalsList.Clear();

Thank you so much you are the greatest!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.