My goal is to produce the average of the numbers a person types into the box (which I have already set up). The equation needs to be after the f.Close(); and the data type needs to be float.
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{
int total = 0, count = 0;
DialogResult result;
result = ofd.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
string fileName = ofd.FileName;
StreamReader f = new StreamReader(fileName);
while (!f.EndOfStream)
{
string textScore = f.ReadLine();
firstScores.Items.Add(textScore);
int score = int.Parse(textScore);
total = total + score;
count = count + 1;
}
f.Close();
//This is what I have currently
float sum, length, average;
string textLine;
sum = float.Parse(textLine);
length = float.Parse(textLine);
average = sum / length;
I thought this might work, but it states that the textLine in the sum = float.Parse is unassigned.