Please Help me with this !!

Updated on May 2, 2017 in [C] Beginner
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on April 30, 2017

i wrote this code to calculate the average , max and min from a text file , i did the read from a text file part but i am having a trouble calculate the max,min and average , can u help me pls???

the Design is :
1 button to get the numbers from the text file and find the min,max and average , 1 list box for the numbers from the file and 3 labels for the answers.

Using List

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 List
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}

//private average(int [] x)
//{

// for (int i = 0; i < x; i++)

//}

private void button1_Click(object sender, EventArgs e)
{
StreamReader input;

List <int> y= new List <int> ();

input = File.OpenText(“TestScores.txt”);
while (!input.EndOfStream)

{
string z = input.ReadLine();
y.Add(int.Parse(z));
listBox1.Items.Add (z);
//MessageBox.Show(x);
}
input.Close();
int sum = 0;
double avg;
int above;
int below;

for (int i = 0; i < y.Count; i++)
{
sum = sum + y[i];

}

avg = (double) sum / y.Count;
listBox1.Items.Add(avg);

}

private void label4_Click(object sender, EventArgs e)
{

}

}
}

  • Liked by
Reply
0 on May 2, 2017

Hey I might not be able to help you but this belongs into the “Answers” category, also use the “Insert Codes” option to display your code to make it easier to read. Last but not least be specific about what your problem is. If you don’t tell us where the problem lies we can’t figure out how to help you.

  • Liked by
Reply
Cancel
0 on May 2, 2017

Do you know whats debugging and breakpoints? you can easily go into lines one by one, and see witch line is wrong… i really recommend watch a youtube video about unity debugging, it really helps you.

  • Liked by
Reply
Cancel