Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Bingo
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. start:
  14. Console.WriteLine("Please put in ten numbers between 1-25. please only use whole numbers." +
  15. (" " + "Please make sure you only write numbers you have not already entered."));
  16. int[] usernumbers = new int[10];
  17.  
  18. for (int i = 0; i <= 9; ++i)
  19. {
  20. int input;
  21. do
  22. {
  23. input = askForInt();
  24. } while (!checkIfUnique(usernumbers, input));
  25. usernumbers[i] = input;
  26. }
  27. // random nr generator
  28. Random boxOfRandomNr = new Random();
  29. int[] randomnumbers = new int[7];
  30. for (int i = 0; i <= 6; ++i)
  31. {
  32. int random;
  33. do
  34. {
  35. random = boxOfRandomNr.Next(1, 26);
  36. } while (!checkIfUnique(randomnumbers, random));
  37. randomnumbers[i] = random;
  38. }
  39. int score = 0;
  40. foreach (int n in usernumbers)
  41. {
  42. if (!checkIfUnique(randomnumbers, n))
  43. {
  44. score += 1;
  45. }
  46. else
  47. {
  48. score += 0;
  49. }
  50. }
  51. Console.WriteLine("Your score: {0}", score);
  52. goto start;
  53. }
  54.  
  55. public static bool checkIfUnique(int[] usernumbers, int input)
  56. {
  57. foreach (int n in usernumbers)
  58. {
  59. if (input == n)
  60. {
  61. return false;
  62. }
  63. }
  64. return true;
  65. }
  66. public static int askForInt()
  67. {
  68. int input = 0;
  69. nrplease:
  70. try
  71. {
  72. input = Convert.ToInt32(Console.ReadLine());
  73.  
  74. }
  75. catch (Exception)
  76. {
  77. Console.WriteLine("Please only use numbers.");
  78. goto nrplease;
  79. }
  80. return input;
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement