Click here to Skip to main content
15,896,557 members
Home / Discussions / C#
   

C#

 
AnswerRe: What is good practice Pin
Bernhard Hiller30-Oct-18 22:49
Bernhard Hiller30-Oct-18 22:49 
QuestionUsing InPlaceBitmapMetadataWriter To Write Keywords Failing on Photos from Recent Cameras Pin
richmhouse29-Oct-18 7:37
richmhouse29-Oct-18 7:37 
QuestionScrolling reset when application regains focus Pin
pr1mem0ver29-Oct-18 2:58
pr1mem0ver29-Oct-18 2:58 
AnswerRe: Scrolling reset when application regains focus Pin
BillWoodruff29-Oct-18 11:55
professionalBillWoodruff29-Oct-18 11:55 
QuestionRookie needs help with array Pin
Member 1398787027-Oct-18 5:28
Member 1398787027-Oct-18 5:28 
AnswerRe: Rookie needs help with array Pin
Richard MacCutchan27-Oct-18 5:54
mveRichard MacCutchan27-Oct-18 5:54 
AnswerRe: Rookie needs help with array Pin
OriginalGriff27-Oct-18 6:12
mveOriginalGriff27-Oct-18 6:12 
GeneralRe: Rookie needs help with array Pin
Member 1398787028-Oct-18 12:39
Member 1398787028-Oct-18 12:39 
Thanks that makes a lot of sense. I can now get the program to compile, but when I click the button to calculate/display I get a message saying "input string was not in a correct format. I think I found the problem string:
while (!inputFile.EndOfStream && index < sales.Length)

I can't seem to fix it though. Any ideas here? Full code for reference:
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 Total_Sales_Homework
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private double Average(int[] iArray)
        {
            double total = 0.0;
            double average;

            for (int index = 0; index < iArray.Length; index++)
            {
                total += iArray[index];
            }

            average = (double)total / iArray.Length;
            return average;
        }

        private double Highest(int[] iArray)
        {
            double highest = iArray[0];

            for (int index = 1; index < iArray.Length; index++)
            {
                if (iArray[index] > highest)
                {
                    highest = iArray[index];
                }
            }

            return highest;
        }

        private double Lowest(int[] iArray)
        {
            double lowest = iArray[0];

            for (int index = 1; index < iArray.Length; index++)
            {
                if (iArray[index] < lowest)
                {
                    lowest = iArray[index];
                }
            }

            return lowest;
        }

        private double Total(double[] iArray)
        {
            double total = iArray[0];
            return total;
        }

        private void salesButton_Click(object sender, EventArgs e)
        {
            try
            {
                double totalSales;
                double highestSales;
                double lowestSales;
                double averageSales;
                StreamReader inputFile;
                const int SIZE = 6;
                int[] sales = new int[SIZE];
                int index = 0;

                inputFile = File.OpenText("Sales.txt");

                while (!inputFile.EndOfStream && index < sales.Length)
                {
                    sales[index] = int.Parse(inputFile.ReadLine());
                    index++;
                }

                inputFile.Close();

                foreach (int value in sales)
                {
                    salesListBox.Items.Add(value);
                }

                totalSales = Highest(sales);
                highestSales = Highest(sales);
                lowestSales = Lowest(sales);
                averageSales = Average(sales);

                totalSalesLabel.Text = totalSales.ToString("n1");
                averageSalesLabel.Text = averageSales.ToString("n1");
                highestSalesLabel.Text = highestSales.ToString("n1");
                smallestSalesLabel.Text = lowestSales.ToString("n1");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

GeneralRe: Rookie needs help with array Pin
OriginalGriff28-Oct-18 20:58
mveOriginalGriff28-Oct-18 20:58 
Question[Solved]How i deserialize a specific JSON with Newtonsoft Pin
Kapparina26-Oct-18 13:35
Kapparina26-Oct-18 13:35 
AnswerRe: How i deserialize a specific JSON with Newtonsoft Pin
josda100026-Oct-18 17:45
josda100026-Oct-18 17:45 
GeneralRe:How i deserialize a specific JSON with Newtonsoft Pin
Kapparina26-Oct-18 18:11
Kapparina26-Oct-18 18:11 
GeneralRe:How i deserialize a specific JSON with Newtonsoft Pin
josda100029-Oct-18 6:10
josda100029-Oct-18 6:10 
QuestionHow do i do this assignment???? Pin
C#NoobHelpMe25-Oct-18 16:49
C#NoobHelpMe25-Oct-18 16:49 
AnswerRe: How do i do this assignment???? Pin
OriginalGriff25-Oct-18 19:29
mveOriginalGriff25-Oct-18 19:29 
AnswerRe: How do i do this assignment???? Pin
Richard MacCutchan25-Oct-18 21:23
mveRichard MacCutchan25-Oct-18 21:23 
JokeRe: How do i do this assignment???? Pin
Peter_in_278025-Oct-18 21:50
professionalPeter_in_278025-Oct-18 21:50 
GeneralRe: How do i do this assignment???? Pin
Richard MacCutchan25-Oct-18 21:52
mveRichard MacCutchan25-Oct-18 21:52 
GeneralRe: How do i do this assignment???? Pin
OriginalGriff26-Oct-18 0:47
mveOriginalGriff26-Oct-18 0:47 
AnswerRe: How do i do this assignment???? Pin
Pete O'Hanlon26-Oct-18 1:40
mvePete O'Hanlon26-Oct-18 1:40 
GeneralRe: How do i do this assignment???? Pin
Eddy Vluggen26-Oct-18 8:33
professionalEddy Vluggen26-Oct-18 8:33 
QuestionBackground worker release resources Pin
udi altman24-Oct-18 8:00
udi altman24-Oct-18 8:00 
AnswerRe: Background worker release resources Pin
OriginalGriff24-Oct-18 20:01
mveOriginalGriff24-Oct-18 20:01 
AnswerRe: Background worker release resources Pin
Eddy Vluggen25-Oct-18 0:45
professionalEddy Vluggen25-Oct-18 0:45 
QuestionDataGridView with scrollbar is flickering Pin
Shine Ashraf23-Oct-18 23:40
Shine Ashraf23-Oct-18 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.