Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 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. using System.Windows.Forms;
  7.  
  8. namespace Ch6Prg1
  9. {
  10. class Ch6Prg1
  11. {
  12. static void Main(string[] args)
  13. {
  14. Header();
  15.  
  16. // these are my integers for the values that will be generated
  17. int minimumValue = 1000;
  18. int maximumValue = 0;
  19. int numEvens = 0;
  20. Random num = new Random(); // this line refers to the random number
  21. string result = "";
  22.  
  23. for (int i = 1; i <= 100; i++ )
  24. {
  25. // in this loop, the if statements allow for random numbers to
  26. // be generated based on calculations and checking to see
  27. // the values of previous generated numbers
  28. int RandomNumber = num.Next(1, 1001);
  29. int evenRem = RandomNumber % 2;
  30. if (evenRem == 0)
  31. {
  32. numEvens++;
  33. }
  34. if (RandomNumber <= minimumValue)
  35. {
  36. minimumValue = RandomNumber;
  37. }
  38. if (RandomNumber >= maximumValue)
  39. {
  40. maximumValue = RandomNumber;
  41. }
  42. // this allows for the result to be developed
  43. result += i + "." + RandomNumber + "\t\t";
  44.  
  45. }
  46. int range = maximumValue - minimumValue;
  47. // this string below concatinates all of the generated values
  48. string total = "Number of Evens: \t" + numEvens
  49. + "\nSmallest number: \t" + minimumValue
  50. + "\nLargest number: \t" + maximumValue + "\nRange: \t" + range;
  51. MessageBox.Show(result + total, "Random Numbers");
  52. // kyle and leon showed me how to use Windows Forms in order to
  53. // display the generated numbers in a message box, thx guys
  54. Footer();
  55.  
  56.  
  57. }
  58. public static void Footer()
  59. {
  60. Console.WriteLine("Please hit any key to continue");
  61. Console.ReadKey();
  62. }
  63. public static void Header()
  64.  
  65. {
  66.  
  67. // hey this is my header its pretty neat
  68. Console.SetWindowSize(100, 60);
  69. Console.ForegroundColor = ConsoleColor.Red;
  70. Console.WriteLine(@" Author:
  71.  
  72. ▄█ ▄██████▄ ▄████████ ▄████████ ███ █▄ ▄████████ ▄████████ ▄██████▄
  73. ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
  74. ███ ███ ███ ███ █▀ ███ ███ ███ ███ ███ █▀ ███ █▀ ███ ███
  75. ███ ███ ███ ▄███▄▄▄ ▄███▄▄▄▄██▀ ███ ███ ███ ███ ███ ███
  76. ███ ███ ███ ▀▀███▀▀▀ ▀▀███▀▀▀▀▀ ███ ███ ▀███████████ ▀███████████ ███ ███
  77. ███ ███ ███ ███ █▄ ▀███████████ ███ ███ ███ ███ ███ ███
  78. ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄█ ███ ▄█ ███ ███ ███
  79. █▄ ▄███ ▀██████▀ ██████████ ███ ███ ████████▀ ▄████████▀ ▄████████▀ ▀██████▀
  80. ▀▀▀▀▀▀ ███ ███
  81. ");
  82.  
  83. Console.ForegroundColor = ConsoleColor.Cyan;
  84. Console.WriteLine(" \t Title: Chapter 10 Program 1 \n");
  85. Console.WriteLine(" \t Date: 5/23/18");
  86. Console.WriteLine(" \t Purpose: To demonstrate usage of loops");
  87. Console.WriteLine(" \t \t in order to generate a number \n");
  88. Console.WriteLine("-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n");
  89.  
  90.  
  91.  
  92. }
  93.  
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement