Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 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 UDEMY_SECTION_4
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //intro to decision structures
  14. int temp = 10;
  15.  
  16. if (temp <10)
  17. {
  18. Console.WriteLine("Take the coat.");
  19. }
  20.  
  21. if (temp == 10)
  22. {
  23. Console.WriteLine("It's 10 degrees C.");
  24. }
  25.  
  26. if (temp >10)
  27. {
  28. Console.WriteLine("Cozy!");
  29. }
  30.  
  31. //37 Intro to TryParse()
  32. string numAsString = "1281";
  33. int numString;
  34. bool success = int.TryParse(numAsString, out numString);
  35.  
  36. if (success)
  37. {
  38. Console.WriteLine("Parsing successful, number is: " + numString);
  39. }
  40. else
  41. {
  42. Console.WriteLine("Failed parsing");
  43. }
  44.  
  45. //38 If & Else If + Try Parse
  46. Console.WriteLine("What's the temperature like?");
  47. string temp2 = Console.ReadLine();
  48. int temp2Num;
  49. int num2;
  50.  
  51. if (int.TryParse(temp2, out num2))
  52. {
  53. temp2Num = num2;
  54. }
  55. else
  56. {
  57. Console.WriteLine("Value entered was not a number. Temperature set to 0.");
  58. temp2Num = 0;
  59. }
  60.  
  61. if (temp2Num < 10)
  62. {
  63. Console.WriteLine("Take the coat.\n");
  64. }
  65. else if (temp2Num == 10)
  66. {
  67. Console.WriteLine("It's 10 degrees C.\n");
  68. }
  69. else if(temp2Num == 30)
  70. {
  71. Console.WriteLine("Boy it's hot.\n");
  72. }
  73. else
  74. {
  75. Console.WriteLine("Cozy!\n");
  76. }
  77.  
  78.  
  79. //39 Nested If Statements
  80. bool isAdmin = false, isRegistered = true;
  81. string userName = "";
  82.  
  83. Console.WriteLine("Enter in user name: ");
  84. userName = Console.ReadLine();
  85.  
  86.  
  87. //you could also add all ofthese into the initial if statement
  88. if (isRegistered)
  89. {
  90. Console.WriteLine("Hi there, registered user!");
  91. if (userName != "")
  92. {
  93. Console.WriteLine("Hi there, " + userName);
  94. if(userName == "Admin")
  95. {
  96. Console.WriteLine("Hi there, Admin!");
  97. }
  98. }
  99.  
  100. }
  101.  
  102. if (isAdmin || isRegistered)
  103. {
  104. Console.WriteLine("You are logged in.\n");
  105. }
  106.  
  107. //40 If Statement Challenge
  108. Console.WriteLine("Create a username: ");
  109. string un = Console.ReadLine();
  110. Console.WriteLine("Create a password: ");
  111. string pw = Console.ReadLine();
  112. Console.WriteLine("Enter in username: ");
  113. string inputUN = Console.ReadLine();
  114. Console.WriteLine("Enter in password: ");
  115. string inputPW = Console.ReadLine();
  116.  
  117. while (inputUN != un && inputPW != pw)
  118. {
  119. Console.WriteLine("Incorrect username or password. Try again.");
  120. Console.WriteLine("Enter in username: ");
  121. inputUN = Console.ReadLine();
  122. Console.WriteLine("Enter in password: ");
  123. inputPW = Console.ReadLine();
  124. if (inputUN == un && inputPW == pw)
  125. {
  126. Console.WriteLine("You are logged in!");
  127. }
  128.  
  129. }
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. Console.Read();
  137. }
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement