Click here to Skip to main content
15,906,106 members
Home / Discussions / C#
   

C#

 
AnswerRe: List of surrounding points Pin
Daniel Pfeffer4-Nov-18 23:53
professionalDaniel Pfeffer4-Nov-18 23:53 
AnswerRe: List of surrounding points Pin
BillWoodruff9-Nov-18 13:26
professionalBillWoodruff9-Nov-18 13:26 
GeneralRe: List of surrounding points Pin
Bernhard Hiller11-Nov-18 21:33
Bernhard Hiller11-Nov-18 21:33 
GeneralRe: List of surrounding points Pin
BillWoodruff11-Nov-18 22:26
professionalBillWoodruff11-Nov-18 22:26 
GeneralRe: List of surrounding points Pin
Bernhard Hiller13-Nov-18 21:57
Bernhard Hiller13-Nov-18 21:57 
GeneralRe: List of surrounding points Pin
BillWoodruff13-Nov-18 22:05
professionalBillWoodruff13-Nov-18 22:05 
GeneralRe: List of surrounding points Pin
Bernhard Hiller13-Nov-18 22:22
Bernhard Hiller13-Nov-18 22:22 
Question[SOLVED] I need help with NIM GAME IN C# Pin
RES7B4-Nov-18 5:23
RES7B4-Nov-18 5:23 
AnswerRe: I need help with NIM GAME IN C# Pin
OriginalGriff1-Nov-18 21:07
mveOriginalGriff1-Nov-18 21:07 
AnswerRe: I need help with NIM GAME IN C# Pin
Eddy Vluggen4-Nov-18 3:48
professionalEddy Vluggen4-Nov-18 3:48 
AnswerRe: [SOLVED] I need help with NIM GAME IN C# Pin
F-ES Sitecore5-Nov-18 2:32
professionalF-ES Sitecore5-Nov-18 2:32 
QuestionHow to update data to existing PDF using Itextsharp library Pin
pondurelakshman30-Oct-18 19:27
pondurelakshman30-Oct-18 19:27 
AnswerRe: How to update data to existing PDF using Itextsharp library Pin
Richard MacCutchan31-Oct-18 3:09
mveRichard MacCutchan31-Oct-18 3:09 
QuestionWhat is good practice Pin
Member 1351454029-Oct-18 9:57
Member 1351454029-Oct-18 9:57 
AnswerRe: What is good practice Pin
BillWoodruff29-Oct-18 11:45
professionalBillWoodruff29-Oct-18 11:45 
SuggestionRe: What is good practice Pin
josda100030-Oct-18 6:51
josda100030-Oct-18 6:51 
GeneralRe: What is good practice Pin
BillWoodruff30-Oct-18 17:08
professionalBillWoodruff30-Oct-18 17:08 
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 
Let me start out by saying I am a complete noob. I am taking an online only course so asking someone a question is very difficult and often takes days to get a response, so I am trying here.

I am tasked with creating an array that pulled sales from a .txt file. All of the sale amounts in the .txt file have decimal amounts, so I figured I would use a double. I am getting all kinds of errors saying I cannot convert a double to an int. I don't know where in the code I have gone wrong. Again, I am completely new to this and understand I probably have multiple issues. Any help would be greatly appreciated.

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(double[] iArray)
        {
            double total = 0.0;
            double average;

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

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

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

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

            return highest;
        }

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

            for (double 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 double SIZE = 7;
                double[] sales = new double[SIZE];
                double 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);
            }
        }
    }
}

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 

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.