I am trying to complete one of my assignments and it requires me to accumulate test score data:
Operation is :
The user enters a score and clicks the Add button or presses the Enter key.
The application calculates and displays the score total, score count, and average score.
If the user clicks the Display scores button, the application sorts the scores 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
SPECS are:
• This application should be able to handle at least 20 scores.
• This application should check the number entered by the user to make sure it is a valid integer from 0 to 100
MY CODE so far looks like this I am having a hard time putting it together:
Here is the pseudo code and some sort of notes for my assignment:
Int[] Array1 = new Array1[20] //this instantiates a new array and takes up to 20 values(per your requirements on your project).
Array1.Sort<int>(array); //this sorts your array in an order *note: this is not optimal for HUGE arrays (say n^2+1) you’ll have to use a compare on it
Foreach(int num in Array1)
{
Writeline(num.ToString()); //shows ALL the scores in the array
}
For the counter:
The “Add” button, you can count how many times that has been pressed, and you can store that in store count. It will not validate unless you put a number, ranging from 0-100, in the field so you can be alright by just counting how many times it has been pressed.
To validate:
Make sure you do a regular expression in the “Score” textbox. Since it says in your requirements, valid integer from 0 to 100. So here goes:
^((100)|(\d{0,2}))$
That regular expression should take care of the other requirement you need for your validation---0 to 100.
Also, make sure that you have a “required field validator” on the score field to make sure it does not take into account the blank values. That will screw up your array.
To sum everything up in the array:
Foreach (int i in Array1)
{
int i;
Int sum = 0;
for(i = m; i<=n; i++)
{
Sum +=x[i];
}
}
To get the average
Sum/total elements in the array.