ЧАСТЬ 1: Я должен создать программу, которая считывает содержимое файла в массив и отображает содержимое массива в элементе управления ListBox, а также рассчитывает и отображает сумму значений массива. - СДЕЛАНО ЭТОЙ ЧАСТЬ
ЧАСТЬ 2: Рассчитайте среднее, максимальное и минимальное значения и отобразите их в элементе управления Label.
Я новичок в кодировании, поэтому ничего не могу поделать, я обращаюсь к переполнению стека за помощью
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace SalesAnalysis
{
public partial class SalesAnalysisApplication : Form
{
public SalesAnalysisApplication()
{
InitializeComponent();
}
private void salesAnalysisButton_Click(object sender, EventArgs e)
{
//declaring array
const int SIZE = 100;
decimal[] sales = new decimal[SIZE];
//varible to hold amount stored in array
int count = 0;
//declaring streamreader
StreamReader inputFile;
//opening the sales file
inputFile = File.OpenText("Sales.txt");
try
{
//pull contents from file into array while there is still
// items to pull and the array isnt full
while (!inputFile.EndOfStream && count < sales.Length)
{
sales[count] = decimal.Parse(inputFile.ReadLine());
count++;
}
//close the file
inputFile.Close();
//display contents in listbox
for (int index = 0; index < count; index++)
{
salesListBox.Items.Add(sales[index]);
}
//Calculate the sum of all values
for (int index = 0; index < sales.Length; index++)
{
totalSales += sales[index];
}
//display total of all values
salesListBox.Items.Add("Total =" + totalSales);
//Determine the average sales from the array
for (int index = 0; index < sales.Length; index++)
{
//calculate the average
averageSales = totalSales / 7;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Clear_Click(object sender, EventArgs e)
{
//Clear all fields
salesListBox.Items.Clear();
averageResultsLabel.Text = "";
highestResultsLabel.Text = "";
lowestResultsLabel.Text = "";
}
private void exitButton_Click(object sender, EventArgs e)
{
//close form
this.Close();
}
}
}