Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. string opnieuw;
  4. //do while loop for if the user wants to run the program again
  5. do
  6. {
  7. //asigns variables
  8. List<int> tenNumbs = new List<int>();
  9. string number;
  10.  
  11. //asks 10 numbers
  12. Console.WriteLine("Geef 10 getallen in.");
  13. for (int i = 1; i < 11; i++)
  14. {
  15. Console.WriteLine("\n" + i + ":");
  16. number = Console.ReadLine();
  17. //checks if the input is the right datatype
  18. if (int.TryParse(number, out int result))
  19. {
  20. tenNumbs.Add(Convert.ToInt32(number));
  21. }
  22. else
  23. {
  24. Console.WriteLine("Het moet een nummer zijn!");
  25. i--;
  26. }
  27. }
  28.  
  29. //calculates
  30. int max = tenNumbs.Max();
  31. int min = tenNumbs.Min();
  32. Console.WriteLine();
  33. Console.WriteLine("--------------------------------------------------------------");
  34. Console.WriteLine();
  35.  
  36. //shows the result
  37. for (int i = 0; i < 10; i++)
  38. {
  39. if (tenNumbs[i] == max)
  40. {
  41. Console.ForegroundColor = ConsoleColor.Blue;
  42. Console.WriteLine(max);
  43. Console.ResetColor();
  44. }
  45. else if(tenNumbs[i] == min)
  46. {
  47. Console.ForegroundColor = ConsoleColor.Red;
  48. Console.WriteLine(min);
  49. Console.ResetColor();
  50. }
  51. else
  52. {
  53. Console.WriteLine(tenNumbs[i]);
  54. }
  55. }
  56.  
  57. //asks if the user wants to run the program again
  58. Console.WriteLine("Wilt u het opnieuw proberen? (ja/nee)");
  59. opnieuw = Console.ReadLine();
  60. //tests if the users input was valid (yes/no)
  61. while (!(opnieuw.ToLower().Contains("ja") || opnieuw.ToLower().Contains("nee")))
  62. {
  63. Console.WriteLine(@"Ongeldig. Geef ""ja"" of ""nee"" in.");
  64. opnieuw = Console.ReadLine();
  65. }
  66. } while (opnieuw.ToLower().Contains("ja"));
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement