mardi 27 décembre 2022

array with random Generator using methods

Hi i'm struggling with this assignment. When the program starts 4 methods are being executed where the next thing hapens.

  • One array gets filled with 100 random numbers between 1 and 1000 000 (method1)
  • The first listbox gets filled with aal the numbers from the array (method2)
  • The second listbox gets filled with the 5 smalest numbers from the array (method3)
  • The third listbox gets filled with the 5 biggest numbers from the array (method3)

This has to run when the program starts.

So far my array gets filled and the first listbox gets filled to. But only in one and not through different methods. i tried to split it up but without succes And my deadline is near.

sorry for the rookie mistakes btw.

public partial class RandomArray : Form
    {   
        int[] arrRandomNumbers = new int[100];
Random randomGenerator = new Random();
        int iRandomNumber = 0;




        public RandomArray()
        {
            InitializeComponent();
           FillArray(arrRandomNumbers);
        }

        
        private void FillArray(int[] array)
        {
            for (int i = 0; i < arrRandomNumbers.Length; i++)

            {

                iRandomNumber = randomGenerator.Next(1, 1000000);

                arrRandomNumbers[i] = iRandomNumber;


            }

        }


        
        private void AddToListBox(int[] array, ListBox box)
        {
            

 foreach (var number in arrRandomNumbers)

                {

                    lbxOne.Items.Add(number);

                }


            


        }
            
                private void AddSmallest(int[] arr, ListBox box)
               {
                  
                   
               } 

            
               private void AddLargest(int[] arr, ListBox box)
            {
                
            }

        
    }

}



Aucun commentaire:

Enregistrer un commentaire