samedi 10 octobre 2015

Simple Windows Application program in C# confusion

My program is messed up bad, and I need help! I already tried c++, and c# is new for me. Experts here at the university said that c# is like c++, and so I tried to widen my perspective on other programming languages other that c++. I tried to make a program that computes the sum of the lowest 3 numbers in 5 inputted numbers on windows application.

to view the design of the windows application is here: Design View

and my messed up code:

namespace Array_excercise
{
   public partial class Form1 : Form
   {
    public Form1()
    {
        InitializeComponent();
    }
    int[] nums = { 0, 0, 0, 0, 0 };
    int[] lownum = { 0, 0, 0,0,0 };
    int[] highnum = { 0, 0, 0, 0, 0 };
    private void computbtn_Click(object sender, EventArgs e)
    {
        nums[0] = Int32.Parse(textBox1.Text);
        nums[1] = Int32.Parse(textBox2.Text);
        nums[2] = Int32.Parse(textBox3.Text);
        nums[3] = Int32.Parse(textBox4.Text);
        nums[4] = Int32.Parse(textBox5.Text);
        int result;
        for (int a = 0; a <= 4; a++)
        {
            if (nums[a] < nums[0])
                lownum[a] = nums[a];
            else if (nums[a] < nums[1])
                lownum[a] = nums[a];
            else if (nums[a] < nums[2])
                lownum[a] = nums[a];
            else if (nums[a] < nums[3])
                lownum[a] = nums[a];
            else if (nums[a] < nums[4])
                lownum[a] = nums[a];
            else
                highnum[a] = nums[a];
        }
    }
}

After that, I don't know how to compute the sum. for now, I'm particularly learning how to use arrays with if and for loop functions. I'll be very grateful if those functions are used in this program.

I thank you in advance!

Aucun commentaire:

Enregistrer un commentaire