-
May 4th, 2013, 04:17 AM
#1
Program help
Im trying to take the numbers from a file display them in a text box and then do calculations with each one which are finding the biggest number out of them, the smallest number and the average. right now i havecreated the form and added the open file to the menu strip and have gotten to load the numbers from the text file into my list box but i cant figure out how to seperate each number individually on their own line in the list box.. here's the code if in anyone is interested in helping. Thanks!
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;
using System.Net;
using System.Xml;
using System.Runtime;
using System.Xml.Serialization;
namespace assignment4
{
public partial class Form1 : Form
{
List<double> numbers;
public Form1()
{
InitializeComponent();
numbers = new List<double>();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
listBox1.Items.Clear();
textBox1.Clear();
string filenumbers;
System.IO.StreamReader sr = new
System.IO.StreamReader(openFileDialog1.FileName);
filenumbers = (sr.ReadToEnd());
listBox1.Items.Add(filenumbers.Split(' '));
sr.Close();
}
string text = "";
foreach (var item in listBox1.Items)
{
text += item.ToString();
}
textBox1.Text = text;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
public double getAverage()
{
double avg = 0.0;
foreach (double temp in numbers)
{
avg += temp;
}
return (avg / numbers.Count());
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|