Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. bool Flag; // Indicator to check if the Array is sorted
  2. int handshake; // Used to hold the number
  3. int count, count2; // Used here instead of inside FOR loops
  4. bool userFlag;
  5. int userHandshake;
  6. int userCount, userCount2;
  7.  
  8. private void btnSubmit_Click(object sender, EventArgs e)
  9. {
  10. // Start of the Array
  11. int[] userNum = new int[6];
  12.  
  13. // Removing the duplicates from within the Array
  14. /*for (userCount2 = 0; userCount2 < userNum.Length; userCount2++)
  15. {
  16. for (userCount = userCount2 + 1; userCount < userNum.Length; userCount2++)
  17. {
  18. if (userNum[userCount2] == userNum[userCount])
  19. {
  20. MessageBox.Show("Duplicate Found!");
  21. return; // we use return to exit out of mulitple loops
  22. }
  23. }
  24. }*/
  25. // Sorting the Array in an Ascending order
  26. userFlag = true;
  27. for (userCount = 1;(userCount <= (userNum.Length)) && userFlag; userCount++)
  28. {
  29. userFlag = false;
  30.  
  31. for (userCount = 0; userCount < userNum.Length - 1; userCount++)
  32. {
  33. if (userNum[userCount] > userNum[userCount + 1])
  34. {
  35. userHandshake = userNum[userCount];
  36. userNum[userCount] = userNum[userCount + 1];
  37. userNum[userCount + 1] = userHandshake;
  38. userFlag = true;
  39. }
  40. }
  41. //get the user input
  42. userNum[0] = int.Parse(User1.Text);
  43. userNum[1] = int.Parse(User2.Text);
  44. userNum[2] = int.Parse(User3.Text);
  45. userNum[3] = int.Parse(User4.Text);
  46. userNum[4] = int.Parse(User5.Text);
  47. userNum[5] = int.Parse(User6.Text);
  48. // Assigning each numbers generated into a textbox
  49. User1.Text = Convert.ToString(userNum[0]);
  50. User2.Text = Convert.ToString(userNum[1]);
  51. User3.Text = Convert.ToString(userNum[2]);
  52. User4.Text = Convert.ToString(userNum[3]);
  53. User5.Text = Convert.ToString(userNum[4]);
  54. User6.Text = Convert.ToString(userNum[5]);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement