Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. namespace Total_Sales_BBrantley
  2. {
  3. public partial class Form1 : Form
  4. {
  5. public Form1()
  6. {
  7. InitializeComponent();
  8. }
  9.  
  10. private void btnCalc_Click(object sender, EventArgs e)
  11. {
  12. try
  13. {
  14. // Declare variable to hold the amount of sales
  15.  
  16. // Declare a constant for the array size
  17. const int SIZE = 100;
  18. // Create an array for the sales
  19. double[] allSales = new double[SIZE];
  20. // Declare a variable for holding the total value of sales
  21. double total = 0.0;
  22. // Declare a variable to hold the average
  23. double average;
  24. // Declare a variable to hold the highest value
  25. double highest = double.MinValue;
  26. // Declare a variable to hold the lowest value
  27. double lowest = double.MaxValue;
  28.  
  29. int count = 0;
  30.  
  31. // Declare a StreamReader variable.
  32. StreamReader readFile;
  33.  
  34. // Open the file and get a StreamReader object using a relative path
  35. readFile = File.OpenText("Sales.txt");
  36.  
  37. while (!readFile.EndOfStream && count < allSales.Length)
  38. {
  39. ERROR ERROR ERROR: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ allSales[count] = int.Parse(readFile.ReadLine()); ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
  40. // Increment count
  41. count++;
  42.  
  43.  
  44. }
  45.  
  46. // Close the file
  47. readFile.Close();
  48.  
  49. lstSales.Items.Add("The file contains " + count + " items:");
  50. for (int index = 0; index < count; index++)
  51. {
  52. lstSales.Items.Add(allSales[index]);
  53.  
  54. }
  55.  
  56.  
  57.  
  58. // Display the total
  59. double sum = allSales.Sum();
  60. lblTotal.Text = sum.ToString();
  61.  
  62. total += sum;
  63. average = total / allSales.Length;
  64. lblAverage.Text = average.ToString();
  65.  
  66. for (int index = 1; index < allSales.Length; index++)
  67. {
  68. if (allSales[index] > highest)
  69. {
  70. highest = allSales[index];
  71. }
  72. lblHighest.Text = highest.ToString();
  73.  
  74. }
  75. for (int index = 1; index < allSales.Length; index++)
  76. {
  77. if (allSales[index] < lowest)
  78. {
  79. lowest = allSales[index];
  80. }
  81. lblLowest.Text = lowest.ToString();
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. // Display an error message on bad input from file
  87. MessageBox.Show(string.Concat("Error calculating the sales. ", ex.Message, "rn", ex.StackTrace));
  88. }
  89.  
  90. }
  91.  
  92. private void btnExit_Click(object sender, EventArgs e)
  93. {
  94. //Closes the application
  95. this.Close();
  96. }
  97. }
  98.  
  99. allSales[count] = int.Parse(readFile.ReadLine());
  100.  
  101. allSales[count] = Double.Parse(readFile.ReadLine());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement