Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 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.  
  8. namespace Assignment_3
  9. {
  10. class Program
  11. {
  12. static void Exercise1()
  13. {
  14. int min;
  15. int max;
  16. var list = new List<int>();
  17. var sum = list.Sum();
  18. Console.WriteLine("Enter minimum integer: ");
  19. min = int.Parse(Console.ReadLine());
  20. Console.WriteLine("Enter maximum integer: ");
  21. max = int.Parse(Console.ReadLine());
  22. while (min <= max && max >= min)
  23. {
  24. Console.WriteLine(min);
  25. min++;
  26. list.Sum(str => Convert.ToInt32(min));
  27. }
  28.  
  29.  
  30. }
  31.  
  32. static void Exercise2()
  33. {
  34.  
  35.  
  36. string entry;
  37. Console.Write("Enter an integer or 'q' to quit ");
  38. entry = Console.ReadLine();
  39.  
  40. while (entry.ToLower() != "q")
  41. {
  42. int number;
  43. if (int.TryParse(entry, out number))
  44. {
  45.  
  46. if (number >= 1 && number <= 10)
  47. {
  48. Dictionary<string, Int32> dictionary = new Dictionary<string, Int32>();
  49. dictionary.Add("1", 1);
  50. dictionary.Add("2", 2);
  51. dictionary.Add("3", 3);
  52. dictionary.Add("4", 4);
  53. dictionary.Add("5", 5);
  54. dictionary.Add("6", 6);
  55. dictionary.Add("7", 7);
  56. dictionary.Add("8", 8);
  57. dictionary.Add("9", 9);
  58. dictionary.Add("10", 10);
  59.  
  60.  
  61. foreach (KeyValuePair<string, int> kvp in dictionary)
  62. {
  63. Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
  64. }
  65.  
  66.  
  67. }
  68. else
  69. {
  70. Console.WriteLine("Your number must be between 1 and 10");
  71. }
  72. }
  73.  
  74.  
  75. Console.Write("Enter an integer or 'q' to quit ");
  76. entry = Console.ReadLine();
  77. }
  78.  
  79. }
  80. static void Main(string[] args)
  81. {
  82. Exercise1();
  83.  
  84. Exercise2();
  85.  
  86. Console.WriteLine("Press enter to end");
  87. Console.ReadLine();
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement