Question
Create an application that reads this file's contents into an array, displays the array's contents in a list box control, and calculates and displays the
Create an application that reads this file's contents into an array, displays the array's contents in a list box control, and calculates and displays the total, average, min, and max of the array's values in a single label.
Sales.txt includes:
1245.67 1189.55 1098.72 1456.88 2109.34 1987.55 1872.36
I am able to display that file's contents in a list box but need help with the rest. Here is my code.
private void MainForm_Load(object sender, EventArgs e) { StreamReader inputFile;
inputFile = File.OpenText("Sales.txt");
int lineCount = File.ReadLines("Sales.txt").Count(); double[] numbers = new double[lineCount];
int index = 0; while (index < numbers.Length && !inputFile.EndOfStream) { numbers[index] = double.Parse(inputFile.ReadLine()); index++; }
inputFile.Close();
foreach (double number in numbers) { salesListBox.Items.Add(number); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started