If you include LINQ(using System.Linq;), it includes an 'Average' method for integer arrays to find the average of every element in the array. You can also extract specific elements that match specific criteria. This link gives a fairly good explanation.
tinstaafl
Nearly a Posting Virtuoso
1,330 posts since Jun 2010
Reputation Points: 355
Solved Threads: 234
Skill Endorsements: 14
To figure out which information you want to print out, the link in my other message gives very easy to understand information with examples on how to program that.
To print out the information, to the screen, not to an actual printer. You can use a temporary pop-up called Message Box, which will display your information until the user clicks and OK button. You can also put a Text Box or a Label on your form in which you can display the information until you change it in your program. If you meant an actual printer you could use the Printer Dialog, which is in your toolbox. It will depend on what your requirements are. Information on how to use these is linked to each one.
tinstaafl
Nearly a Posting Virtuoso
1,330 posts since Jun 2010
Reputation Points: 355
Solved Threads: 234
Skill Endorsements: 14
There's a link in my last message about Text Boxes. They are fairly straight forward basically TextBox1.Text=AnyString. Like any string variable if you want to add to the string, TextBox1.Text = TextBox1.Text + AnyString.
tinstaafl
Nearly a Posting Virtuoso
1,330 posts since Jun 2010
Reputation Points: 355
Solved Threads: 234
Skill Endorsements: 14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
double[] MyArray = new double[]{10,9,5,77,45,23,12,5,88,49};
double wrecked = MyArray.Average();
int lowerthanAv = 0, higherthanAv = 0;
for (int i = 0; i < MyArray.Length; i++)
{
if (MyArray[i] < wrecked)
lowerthanAv++;
else
higherthanAv++; // I do not take equal than av into acount here
}
Console.WriteLine("The average is: {0}", wrecked);
Console.WriteLine("Number lower than average: {0}", lowerthanAv);
Console.WriteLine("Number higher than average: {0}", higherthanAv);
Console.ReadLine();
}
}
}
I think the above code does what you like to do.
ddanbe
Industrious Poster
4,294 posts since Oct 2008
Reputation Points: 2,121
Solved Threads: 723
Skill Endorsements: 26
Here you go sorry for the confusion I think this gives you what you want.
int[] ArrNumbers = new int[] { 10, 9, 5, 77, 45, 23, 12, 5, 88, 49 };
int min = ArrNumbers.Min();
int max = ArrNumbers.Max();
double average = ArrNumbers.Average();
string higher = "", lower = "", equal = "";
for (int i = 0; i < ArrNumbers.Length - 1; i++)
{
if (ArrNumbers[i] < average)
{
lower = lower + Convert.ToString(ArrNumbers[i]) + " ";
}
else
{
if (ArrNumbers[i] > average)
{
higher = higher + Convert.ToString(ArrNumbers[i]) + " ";
}
else
{
equal = equal + Convert.ToString(ArrNumbers[i]) + " ";
}
}
}
textBox1.Lines = new string[] { "Minimum - " + min, "Maximum - " + max, "Average - " + average, "Lower - " + lower, "Higher - " + higher, "Equal - " + equal };
the output in the textbox is:
Minimum - 5
Maximum - 88
Average - 32.3
Lower - 10 9 5 23 12 5
Higher - 77 45 88
Equal -
tinstaafl
Nearly a Posting Virtuoso
1,330 posts since Jun 2010
Reputation Points: 355
Solved Threads: 234
Skill Endorsements: 14
Question Answered as of 5 Months Ago by
tinstaafl
and
ddanbe