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.

Recommended Answers

All 9 Replies

So whats wrong? Just implement what you have written down.

I am having a hard time implementing it okay here is the deal I have 4 labels Score: text box that requires input:
Score total: textbox r/o
Score Count: textbox r/o
Average: textbox r/o

Then I have 4 buttons. a Display scores:
Clear Scores:
Exit:
Add:

Then a pop up window that needs Sorted Scores...

I know what I am suppose to do but I am have trouble with what code goes where.

I got the code for the exit button which is:
this.button2.Click += new System.EventHandler(this.button2_Click);
this.Close();

I got that far please help

Try working on the core (non-gui) parts of you program first. If you have a problem you can't solve, send the code here to learn how to solve it. Have a good day :)

What do you mean non gui parts which button does the code have to go in the display code or the add

I got the code for the exit button which is:
this.button2.Click += new System.EventHandler(this.button2_Click);
this.Close();

The code will compile, but it seems to me like you are blinded and then try to break an egg with a stick. Are you using VS 2008 C# or a C# command line compiler?
Please specify.

MY CODE so far looks like this I am having a hard time putting it together:

Oh man, seems this is going to be a long way to Tipperary...
Just your first "line":
Int[] Array1 = new Array1[20]
1>> Int must be int. C# is case sensitive.
2>> Array1 as variable name is fine, but a more descriptive name like Scores would be better.
3>> Array1 is no type recognised in the .NET environment and would not be compatible with the int array you declared. Use int here.
4>> You missed a ;
So your statement would become :
int[] Scores= new int[20];

And BTW arrays are a bit outdated these days, better use something like :
List<int> Scores= new List<int>();

Thanks thats a start to help me clarify that. I am using VB C# 2008 so when I enter this array will it be in the button Display Scores:

What code is used for the add button

and do I need a message shadow code to hae the Sorted Scores pop up

I know I am a blind cat trying to do code its so confusing

Perhaps you should read a book like this one.

Did you notice you have a help menu in VS 2008?
Click it and select Search In the window that opens type List you will ge info about the generic list class together with code examples.

Now if you have a Forms application with an Add button on it in design mode, doubleclick the button and see what happens:-O
Do the same with your other buttons.

Experiment! Have fun!
Try to figure some things out for yourself.
If you have further problems or questions you are more than welcome here.

As opposed to Hiroshe I like to work out an application with pencil and paper. I don't even think of coding. I ask myself what do I need? This is a result of all my scribbling, translated in VS 2008 (see pict) Now I'm back in with Hiroshe. Now I'm gonna ask my self : what has the add button got to do?
And so on for the other element of my design.

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.