Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Total_Sales_BBrantley
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnCalc_Click(object sender, EventArgs e)
- {
- try
- {
- // Declare variable to hold the amount of sales
- // Declare a constant for the array size
- const int SIZE = 100;
- // Create an array for the sales
- double[] allSales = new double[SIZE];
- // Declare a variable for holding the total value of sales
- double total = 0.0;
- // Declare a variable to hold the average
- double average;
- // Declare a variable to hold the highest value
- double highest = double.MinValue;
- // Declare a variable to hold the lowest value
- double lowest = double.MaxValue;
- int count = 0;
- // Declare a StreamReader variable.
- StreamReader readFile;
- // Open the file and get a StreamReader object using a relative path
- readFile = File.OpenText("Sales.txt");
- while (!readFile.EndOfStream && count < allSales.Length)
- {
- ERROR ERROR ERROR: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ allSales[count] = int.Parse(readFile.ReadLine()); ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
- // Increment count
- count++;
- }
- // Close the file
- readFile.Close();
- lstSales.Items.Add("The file contains " + count + " items:");
- for (int index = 0; index < count; index++)
- {
- lstSales.Items.Add(allSales[index]);
- }
- // Display the total
- double sum = allSales.Sum();
- lblTotal.Text = sum.ToString();
- total += sum;
- average = total / allSales.Length;
- lblAverage.Text = average.ToString();
- for (int index = 1; index < allSales.Length; index++)
- {
- if (allSales[index] > highest)
- {
- highest = allSales[index];
- }
- lblHighest.Text = highest.ToString();
- }
- for (int index = 1; index < allSales.Length; index++)
- {
- if (allSales[index] < lowest)
- {
- lowest = allSales[index];
- }
- lblLowest.Text = lowest.ToString();
- }
- }
- catch (Exception ex)
- {
- // Display an error message on bad input from file
- MessageBox.Show(string.Concat("Error calculating the sales. ", ex.Message, "rn", ex.StackTrace));
- }
- }
- private void btnExit_Click(object sender, EventArgs e)
- {
- //Closes the application
- this.Close();
- }
- }
- allSales[count] = int.Parse(readFile.ReadLine());
- allSales[count] = Double.Parse(readFile.ReadLine());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement