Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
heey
I have an assinment for collage for a coarse called " visual programming" we use the " visual c# "
i have done it but still have one single problem which is how to calculate the average of the items i added in the list box

{it is like we have a textbox and each time i suppose to type a grage of a student" and when i click in the average button it has to calculate the average and display it in a lable}:confused: :confused:

my problem is i couldn't figure out how to do the average thing :((
Posted

i know how to caculate the average

private void Average_Click(object sender, EventArgs e)<br />
        {<br />
            <br />
            double sum = 0;<br />
            //Listboxth.Items = int.Parse();<br />
            for (int i = 0; i < Listboxth.Items.Count; i++)<br />
                sum += Listboxth.Items.IndexOf(i);<br />
            average = sum / Listboxth.Items.Count;<br />
<br />
        }


this is how i did it ... but still don't know if it worked .. :s

and i couldn't figure out how to display the average in the lable:

private void label2_Click(object sender, EventArgs e)<br />
        {<br />
            string avrg;<br />
            avrg = average;<br />
            label2.Text = avrg;<br />
        }


^ i know there is something wrong with the conversion maybe X|

btw i am new in programming and visual programming just started two monthes ago ..
 
Share this answer
 
Add the values together to get the sum and divide by the number of values to get the average. Elementary mathematics really.
 
Share this answer
 
Add up all the values, then divide that number by the total number of values added. For example, given these 3 values:
1
2
3

You add them up: 1 + 2 + 3 = 6
Then you divide them by the total number of items: 6 / 3 = 2.
So the average is 2.
 
Share this answer
 
<sarcasm>It's times like these when I wish that Code Project Answers was around to help me do MY homework for college... *sigh*
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900