I am trying to create a program in windows forms and i am almost done by my array will not store numbers. It will only use the last number entered. Please help, i did this program in c sharp without a problem but cant figure out windows forms application.
public partial class Form1 : Form
{
int[] vars=new int[5];
int integersEntered;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
vars[4] = int.Parse(NosArray.Text);
Integer.Text = integersEntered.ToString();
integersEntered++;
NosArray.Text = String.Empty;
NosArray.Focus();
}
private void Integer_TextChanged(object sender, EventArgs e)
{
}
private void NosArray_TextChanged(object sender, EventArgs e)
{
}
private void Var_Click(object sender, EventArgs e)
{
float avg = (vars[0] + vars[1] + vars[2] + vars[3] + vars[4] / 5);
OutputLabel1.Text = " the average of the numbers " + vars[0] + ", " + vars[1] +
", " + vars[2] + ", " + vars[3] + " and " + vars[4] + " is " +
avg.ToString();
OutputLabel1.Visible = true;
OutputLabel2.Visible = true;
Avg.Visible = true;
Var.Visible = true;
float Variance = ((((((((((vars[0]) - avg) * (vars[0]) - avg)) + ((vars[1]) - avg) * (vars[1]) - avg)) + ((vars[2]) - avg) * (vars[2]) - avg)) + ((vars[3] - avg) * (vars[3] - avg)) + ((vars[4]) - avg) * (vars[4]) - avg) / 4);
OutputLabel2.Text = "The Variance is " + Variance.ToString();
}
private void Avg_Click(object sender, EventArgs e)
{
}
}
}