Need big help, tried almost everything, I need to put a string together, that contains all my returned calculated functions in a textBox. As you can see I have a menuToolStrip option that when I click, it will show the list of my calculated functions, I want it to show them one by one verticaly on different lines. It does not work and I dont know why. Please advise, thanks
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace test
{
public partial class Form1 : Form
{
//A list to put all the data values(.txt file) opened
List<double> dataValues = new List<double>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
//Choose the data file to open for calculation
private void ouvrirToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ofd.ShowDialog(this) == DialogResult.OK)
{
FileStream fs = new FileStream(ofd.FileName, FileMode.Open);
StreamReader sr = new StreamReader(fs);
String nbr;
while ((nbr = sr.ReadLine()) != null)
{
double data = 0.0;
if ((double.TryParse(nbr, out data)))
dataValues.Add(data);
//textBox1.Text += nbr.ToString() + "\r\n";
//Console.WriteLine(data);
}
sr.Close();
fs.Close();
}
}
public double std(List<double> dataValues)
{
double average = 0.0;
foreach (double d in dataValues)
{
average += d;
}
average /= (double)dataValues.Count;
//Calculate standard deviation
List<double> stdDev = new List<double>();
foreach (double d in dataValues)
{
stdDev.Add(Math.Pow((d - average), 2));
}
//Sum of all values, divide by the average and take sqrt to get std
double standardDeviation = Math.Sqrt((stdDev.Sum() / average));
return standardDeviation;
}
//Calculate the average of the data in the list
private double getAverage(List<double> dataValues)
{
double total = 0;
foreach (double value in dataValues)
{
total += value;
}
double average = total / dataValues.Count;
return average;
}
public void sommeToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Text += "ecartType = " + std(dataValues) + "Moyenne = " + getAverage(dataValues);
}
Comment