Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,920 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,575 people online right now. Registration is fast and FREE... Join Now!




arraylist

 
Reply to this topicStart new topic

arraylist

ahpoohbear
18 May, 2008 - 06:32 AM
Post #1

New D.I.C Head
*

Joined: 6 May, 2008
Posts: 4

hi smile.gif

in my program, i need to get the values from the user via a textbox and then to add the value from the textbox into an array.

is this the right way to put the values inside the array?


CODE

             foreach (double tempValue in txtGrade.Text)
             {
                 gradesAL.Add(tempValue);
             }


i've already created one array and one arraylist:

CODE

private double[] Grades = new double[] { };

        private ArrayList gradesAL = new ArrayList();


is this the correct way?

so let's assume that I've added the values into the arraylist (which I doubt so). and i need to find the average of all the arrays. Is this the right way?

CODE
private void btnStats_Click(object sender, EventArgs e)
        {
            double sumAverage;
            double sumScore;
            

            sumScore = 0;
            try
            {
                //to get the average value.
                for (int i = 0; i < Grades.Length; i++)
                {
                    
                    sumScore =+ Grades[i];
                    sumAverage = Math.Truncate(sumScore / gradesAL.Count);
                    txtAverage.Text = sumAverage.ToString();

                }
            }
            catch (Exception ex)
            {
                msgBox("Error: " + ex.Message);
            }


thanks..need assistance urgently. sorry for the trouble as I'm very new to c#.

thanks and cheers smile.gif
pooh
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Arraylist
18 May, 2008 - 08:16 AM
Post #2

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 349



Thanked: 19 times
Dream Kudos: 25
My Contributions
do you have multiple textboxes for the user to input the grades into? or are they going to be inputting multiple grades into one textbox?
User is offlineProfile CardPM
+Quote Post

ahpoohbear
RE: Arraylist
18 May, 2008 - 09:02 AM
Post #3

New D.I.C Head
*

Joined: 6 May, 2008
Posts: 4

QUOTE(eclipsed4utoo @ 18 May, 2008 - 09:16 AM) *

do you have multiple textboxes for the user to input the grades into? or are they going to be inputting multiple grades into one textbox?


option 2, input multiple grades into one textbox. thx.
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Arraylist
18 May, 2008 - 03:40 PM
Post #4

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 349



Thanked: 19 times
Dream Kudos: 25
My Contributions
QUOTE(ahpoohbear @ 18 May, 2008 - 10:02 AM) *

QUOTE(eclipsed4utoo @ 18 May, 2008 - 09:16 AM) *

do you have multiple textboxes for the user to input the grades into? or are they going to be inputting multiple grades into one textbox?


option 2, input multiple grades into one textbox. thx.


then you are going to need to split the data in the textbox.

lets say that they put data into the texbox like this: 90, 84, 74, 85.....then you would need to do this.

C#

double score = 0;
double sum = 0;

string[] gradesArray = txtGrades.Text.Split(',');

for (int i = 0; i < gradesArray.Length; i++)
{
if (Double.TryParse(gradesArray[i].Trim(), out score))
{
sum += score;
}
}

txtAverage.Text = Convert.ToString(Math.Truncate(sum / gradesArray.Length));


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:07AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month