Advertisement
Guest User

task 2

a guest
Jun 19th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 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 ConsoleApp12
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. space(false, 0);
  14.  
  15. }
  16. static void space(bool spaced, int amount)
  17. {
  18. int num;
  19. Console.WriteLine("Please enter a number representing a month of the year (Jan = 1, Feb = 2, ect.)");
  20. if (spaced == true)
  21. {
  22. for (int i = 0; i < amount; i++)
  23. Console.WriteLine("\n");
  24. }
  25. string trymonth = Console.ReadLine();
  26.  
  27. if (int.TryParse(trymonth, out num) && int.Parse(trymonth) < 13 && int.Parse(trymonth) > 0)
  28. {
  29. int month = int.Parse(trymonth);
  30. year(month);
  31. }
  32. else
  33. {
  34. Console.WriteLine("Enter a valid input and try again.");
  35. space(true, 13);
  36. }
  37.  
  38.  
  39. }
  40.  
  41. static void year(int month)
  42. {
  43. int num;
  44. Console.WriteLine("Please input the year you wish to search.");
  45. string tryyear = Console.ReadLine();
  46.  
  47. if (int.TryParse(tryyear, out num) && int.Parse(tryyear) > -1)
  48. {
  49. int year = int.Parse(tryyear);
  50. testleap(month, year);
  51. }
  52. else
  53. {
  54. Console.WriteLine("Enter a valid input and try again.");
  55. space(true, 13
  56. );
  57. }
  58.  
  59.  
  60.  
  61. }
  62. static void testleap(int month, int year)
  63. {
  64. if (month == 2 && year % 4 == 0)
  65. {
  66. if (year % 100 != 0 || year % 400 == 0)
  67. {
  68. Console.WriteLine("During February in " + year + " there are 29 days.");
  69. }
  70. else
  71. {
  72. notleap(month, year);
  73. }
  74. }
  75. else
  76. {
  77. notleap(month, year);
  78. }
  79. Console.WriteLine("Press any key to continue");
  80. Console.ReadKey();
  81. }
  82. static void notleap(int month, int year)
  83. {
  84. switch (month)
  85. {
  86. case 1:
  87. Console.WriteLine("During January in " + year + " there are 31 days.");
  88. break;
  89. case 2:
  90. Console.WriteLine("During February in " + year + " there are 28 days.");
  91. break;
  92. case 3:
  93. Console.WriteLine("During March in " + year + " there are 31 days.");
  94. break;
  95. case 4:
  96. Console.WriteLine("During April in " + year + " there are 30 days.");
  97. break;
  98. case 5:
  99. Console.WriteLine("During May in " + year + " there are 31 days.");
  100. break;
  101. case 6:
  102. Console.WriteLine("During June in " + year + " there are 29 days.");
  103. break;
  104. case 7:
  105. Console.WriteLine("During July in " + year + " there are 31 days.");
  106. break;
  107. case 8:
  108. Console.WriteLine("During August in " + year + " there are 31 days.");
  109. break;
  110. case 9:
  111. Console.WriteLine("During September in " + year + " there are 30 days.");
  112. break;
  113. case 10:
  114. Console.WriteLine("During October in " + year + " there are 31 days.");
  115. break;
  116. case 11:
  117. Console.WriteLine("During November in " + year + " there are 30 days.");
  118. break;
  119. case 12:
  120. Console.WriteLine("During December in " + year + " there are 31 days.");
  121. break;
  122. }
  123.  
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement