Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Flag; // Indicator to check if the Array is sorted
- int handshake; // Used to hold the number
- int count, count2; // Used here instead of inside FOR loops
- bool userFlag;
- int userHandshake;
- int userCount, userCount2;
- private void btnSubmit_Click(object sender, EventArgs e)
- {
- // Start of the Array
- int[] userNum = new int[6];
- // Removing the duplicates from within the Array
- /*for (userCount2 = 0; userCount2 < userNum.Length; userCount2++)
- {
- for (userCount = userCount2 + 1; userCount < userNum.Length; userCount2++)
- {
- if (userNum[userCount2] == userNum[userCount])
- {
- MessageBox.Show("Duplicate Found!");
- return; // we use return to exit out of mulitple loops
- }
- }
- }*/
- // Sorting the Array in an Ascending order
- userFlag = true;
- for (userCount = 1;(userCount <= (userNum.Length)) && userFlag; userCount++)
- {
- userFlag = false;
- for (userCount = 0; userCount < userNum.Length - 1; userCount++)
- {
- if (userNum[userCount] > userNum[userCount + 1])
- {
- userHandshake = userNum[userCount];
- userNum[userCount] = userNum[userCount + 1];
- userNum[userCount + 1] = userHandshake;
- userFlag = true;
- }
- }
- //get the user input
- userNum[0] = int.Parse(User1.Text);
- userNum[1] = int.Parse(User2.Text);
- userNum[2] = int.Parse(User3.Text);
- userNum[3] = int.Parse(User4.Text);
- userNum[4] = int.Parse(User5.Text);
- userNum[5] = int.Parse(User6.Text);
- // Assigning each numbers generated into a textbox
- User1.Text = Convert.ToString(userNum[0]);
- User2.Text = Convert.ToString(userNum[1]);
- User3.Text = Convert.ToString(userNum[2]);
- User4.Text = Convert.ToString(userNum[3]);
- User5.Text = Convert.ToString(userNum[4]);
- User6.Text = Convert.ToString(userNum[5]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement