Advertisement
Guest User

yep

a guest
Sep 5th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.64 KB | None | 0 0
  1. Module Module1
  2. Dim valid As Boolean
  3. Sub Main()
  4. Dim test As Integer
  5. Dim areapos As Integer
  6. Dim area As Integer
  7. Userpass()
  8. shapechoice(test)
  9. guessoptions(test, areapos, area)
  10. points(areapos, test, area)
  11. End Sub
  12. Sub Userpass()
  13. Dim username As String
  14. Dim password As String
  15. Dim character As Char
  16. Dim stepper As Integer
  17. Dim digit As Boolean
  18. 'Do Until valid = True
  19. ' test = rand.Next(15)
  20. ' Console.WriteLine(test)
  21. ' Console.ReadLine()
  22. 'Loop
  23.  
  24. Console.WriteLine("Welcome to the area trainer!" & vbNewLine)
  25. Console.WriteLine("Please enter your username to start:")
  26. username = Console.ReadLine 'allows input of username
  27. Do Until valid = True 'loops until a password of appropriate strength is entered
  28. valid = False
  29. Console.WriteLine("Please enter your password:")
  30. Console.WriteLine("(It must be atleast 7 digits long and contain a number)")
  31. password = Console.ReadLine
  32. If Len(password) >= 7 Then 'makes sure the password entered is atleast 7 digits long
  33. stepper = 1
  34. character = Mid(password, stepper, 1)
  35. If Char.IsDigit(character) Then 'makes sure the password entered contains a number
  36. digit = True
  37. End If
  38. If digit = True Then
  39. valid = True
  40. Else
  41. Console.WriteLine("Make sure your password contains a number" & vbNewLine)
  42. End If
  43. Else
  44. Console.WriteLine("Your password was not atleast 7 digits long,")
  45. Console.WriteLine("Please try again." & vbNewLine)
  46. Console.WriteLine("PRESS ENTER TO CONTINUE")
  47. Console.ReadLine()
  48. Console.Clear()
  49. End If
  50. Loop
  51. Console.Clear()
  52. Console.WriteLine("Logged in" & vbNewLine)
  53. End Sub
  54. Sub shapechoice(ByRef test As Integer)
  55. Dim choice As Char
  56.  
  57. valid = False
  58. Do Until valid = True 'loops until a valid number is entered as a choice
  59. Console.WriteLine("Now enter the number of the shape you want to train with:")
  60. Console.WriteLine("1: Square")
  61. Console.WriteLine("2: Circle")
  62. Console.WriteLine("3: Triangle")
  63. choice = Console.ReadLine
  64. If Char.IsDigit(choice) Then 'checks that the userinput is a number
  65. test = Left(choice, 1) 'converts the char to an integer
  66. 'Console.WriteLine(test)
  67. Select Case test 'checks that the number is 1, 2 or 3
  68. Case "1"
  69. valid = True
  70. Case "2"
  71. valid = True
  72. Case "3"
  73. valid = True
  74. Case Else
  75. Console.WriteLine("")
  76. Console.WriteLine("Make sure you enter a number between 1 and 3 inclusive")
  77. Console.WriteLine("Please try again:" & vbNewLine)
  78. End Select
  79. Else
  80. Console.WriteLine("")
  81. Console.WriteLine("Make sure you are entering a number")
  82. Console.WriteLine("Please try again:" & vbNewLine)
  83. End If
  84. Loop
  85. End Sub
  86. Sub guessoptions(ByVal test As Integer, ByRef areapos As Integer, ByRef area As Integer)
  87. Dim rand As New Random
  88. Dim position As Integer
  89. Dim length, width As Integer
  90. Dim option1, option2, option3 As Integer
  91.  
  92. Select Case test
  93. Case "1" 'all the code for the square
  94. Do Until length > 0 'makes sure length is not 0
  95. length = rand.Next(15)
  96. Loop
  97. Do Until width > 0 'makes sure width is not 0
  98. width = rand.Next(15)
  99. Loop
  100.  
  101. area = length * width 'calculates area of the square
  102. 'Console.WriteLine(area)
  103. valid = False
  104. Do Until valid = True 'generates each incorrect answer and makes sure they are all different from each other and the area
  105. option1 = rand.Next(197)
  106. If option1 <> area Then
  107. valid = True
  108. End If
  109. Loop
  110. valid = False
  111. Do Until valid = True
  112. option2 = rand.Next(197)
  113. If option2 <> area Then
  114. If option2 <> option1 Then
  115. valid = True
  116. End If
  117. End If
  118. Loop
  119. valid = False
  120. Do Until valid = True
  121. option3 = rand.Next(197)
  122. If option3 <> area Then
  123. If option3 <> option1 Then
  124. If option3 <> option2 Then
  125. valid = True
  126. End If
  127. End If
  128. End If
  129. Loop
  130. Console.WriteLine("The length of the square is: " & length & "cm and the width of the square is: " & width & "cm")
  131. Console.WriteLine("Input the number for the answer that you think is the correct area")
  132. position = rand.Next(4) 'generates a random number to put the correct answer in a random position
  133.  
  134. Select Case position 'writes out the list of 4 possible answers
  135. Case "0"
  136. Console.WriteLine("1. " & area)
  137. Console.WriteLine("2. " & option1)
  138. Console.WriteLine("3. " & option2)
  139. Console.WriteLine("4. " & option3)
  140. areapos = 1
  141. Case "1"
  142. Console.WriteLine("1. " & option1)
  143. Console.WriteLine("2. " & area)
  144. Console.WriteLine("3. " & option2)
  145. Console.WriteLine("4. " & option3)
  146. areapos = 2
  147. Case "2"
  148. Console.WriteLine("1. " & option1)
  149. Console.WriteLine("2. " & option2)
  150. Console.WriteLine("3. " & area)
  151. Console.WriteLine("4. " & option3)
  152. areapos = 3
  153. Case "3"
  154. Console.WriteLine("1. " & option1)
  155. Console.WriteLine("2. " & option2)
  156. Console.WriteLine("3. " & option3)
  157. Console.WriteLine("4. " & area)
  158. areapos = 4
  159. End Select
  160.  
  161. Case "2"
  162. Do Until length > 0 'makes sure length is not 0
  163. length = rand.Next(15)
  164. Loop
  165.  
  166. area = 3.14 * (length * length) 'works out the area of the circle
  167. 'Console.WriteLine(area)
  168. valid = False
  169. Do Until valid = True 'generates each incorrect answer and makes sure they are all different from each other and the area
  170. option1 = rand.Next(616)
  171. If option1 <> area Then
  172. valid = True
  173. End If
  174. Loop
  175. valid = False
  176. Do Until valid = True
  177. option2 = rand.Next(616)
  178. If option2 <> area Then
  179. If option2 <> option1 Then
  180. valid = True
  181. End If
  182. End If
  183. Loop
  184. valid = False
  185. Do Until valid = True
  186. option3 = rand.Next(616)
  187. If option3 <> area Then
  188. If option3 <> option2 Then
  189. If option3 <> option1 Then
  190. valid = True
  191. End If
  192. End If
  193. End If
  194. Loop
  195. Console.WriteLine("The radius of the circle is " & length & "cm")
  196. Console.WriteLine("Assuming pi is 3.14 and all answers are rounded to the nearest integer")
  197. Console.WriteLine("Input the number for the answer that you think is the correct area")
  198. position = rand.Next(4) 'generates a random number to put the correct answer in a random position
  199.  
  200. Select Case position 'writes out the list of 4 possible answers
  201. Case "0"
  202. Console.WriteLine("1. " & area)
  203. Console.WriteLine("2. " & option1)
  204. Console.WriteLine("3. " & option2)
  205. Console.WriteLine("4. " & option3)
  206. areapos = 1
  207. Case "1"
  208. Console.WriteLine("1. " & option1)
  209. Console.WriteLine("2. " & area)
  210. Console.WriteLine("3. " & option2)
  211. Console.WriteLine("4. " & option3)
  212. areapos = 2
  213. Case "2"
  214. Console.WriteLine("1. " & option1)
  215. Console.WriteLine("2. " & option2)
  216. Console.WriteLine("3. " & area)
  217. Console.WriteLine("4. " & option3)
  218. areapos = 3
  219. Case "3"
  220. Console.WriteLine("1. " & option1)
  221. Console.WriteLine("2. " & option2)
  222. Console.WriteLine("3. " & option3)
  223. Console.WriteLine("4. " & area)
  224. areapos = 4
  225. End Select
  226.  
  227. Case "3"
  228. Do Until length > 0 'makes sure length is 0
  229. length = rand.Next(15)
  230. Loop
  231. Do Until width > 0 'makes sure width is 0
  232. width = rand.Next(15)
  233. Loop
  234.  
  235. area = (length / 2) * width 'works out the area of the triangle
  236. 'Console.WriteLine(area)
  237. valid = False
  238. Do Until valid = True 'generates each incorrect answer and makes sure they are all different from each other and the area
  239. option1 = rand.Next(99)
  240. If option1 <> area Then
  241. valid = True
  242. End If
  243. Loop
  244. valid = False
  245. Do Until valid = True
  246. option2 = rand.Next(99)
  247. If option2 <> area Then
  248. If option2 <> option1 Then
  249. valid = True
  250. End If
  251. End If
  252. Loop
  253. valid = False
  254. Do Until valid = True
  255. option3 = rand.Next(99)
  256. If option3 <> area Then
  257. If option3 <> option2 Then
  258. If option3 <> option1 Then
  259. valid = True
  260. End If
  261. End If
  262. End If
  263. Loop
  264. Console.WriteLine("The base of the triangle is " & length & "cm and the height of the triangle is " & width & "cm")
  265. Console.WriteLine("Input the number for the answer that you think is the correct area")
  266. position = rand.Next(4) 'generates a random number to put the correct answer in a random position
  267.  
  268. Select Case position 'writes out the list of 4 possible answers
  269. Case "0"
  270. Console.WriteLine("1. " & area)
  271. Console.WriteLine("2. " & option1)
  272. Console.WriteLine("3. " & option2)
  273. Console.WriteLine("4. " & option3)
  274. areapos = 1
  275. Case "1"
  276. Console.WriteLine("1. " & option1)
  277. Console.WriteLine("2. " & area)
  278. Console.WriteLine("3. " & option2)
  279. Console.WriteLine("4. " & option3)
  280. areapos = 2
  281. Case "2"
  282. Console.WriteLine("1. " & option1)
  283. Console.WriteLine("2. " & option2)
  284. Console.WriteLine("3. " & area)
  285. Console.WriteLine("4. " & option3)
  286. areapos = 3
  287. Case "3"
  288. Console.WriteLine("1. " & option1)
  289. Console.WriteLine("2. " & option2)
  290. Console.WriteLine("3. " & option3)
  291. Console.WriteLine("4. " & area)
  292. areapos = 4
  293. End Select
  294. End Select
  295. End Sub
  296. Sub points(ByVal areapos As Integer, ByRef test As Integer, ByVal area As Integer)
  297. Dim guess As Char
  298. Dim points As Integer
  299. points = 0
  300.  
  301. valid = False
  302. Do Until valid = True 'loops until a valid guess is entered
  303. guess = Console.ReadLine
  304.  
  305. If Char.IsDigit(guess) Then 'make sure the guess is a number
  306. test = Left(guess, 1) 'converts the char to an integer
  307. Select Case test 'makes sure the guess is 1, 2, 3 or 4
  308. Case "1"
  309. valid = True
  310. Case "2"
  311. valid = True
  312. Case "3"
  313. valid = True
  314. Case "4"
  315. valid = True
  316. Case Else
  317. Console.WriteLine("")
  318. Console.WriteLine("Make sure you enter a number between 1 and 4 inclusive")
  319. Console.WriteLine("Please try again:" & vbNewLine)
  320. End Select
  321. Else
  322. Console.WriteLine("")
  323. Console.WriteLine("Make sure you are entering a number")
  324. Console.WriteLine("Please try again:" & vbNewLine)
  325. End If
  326. Loop
  327. 'Console.WriteLine("valid")
  328.  
  329. If test = areapos Then 'checks if the guess is equal to the position of the correct answer
  330. points = points + 2 'adds to points for a first time guess
  331. Console.WriteLine("You guessed the correct answer and earned 2 points")
  332. Else
  333. Console.WriteLine("You entered an incorrect answer, try again") 'allows a second guess if the first was wrong
  334. valid = False
  335. Do Until valid = True 'loops until a valid guess is entered
  336. guess = Console.ReadLine
  337. If Char.IsDigit(guess) Then 'makes sure the guess is a number
  338. test = Left(guess, 1) 'converts the char to an integer
  339. Select Case test 'makes sure the guess is 1, 2, 3 or 4
  340. Case "1"
  341. valid = True
  342. Case "2"
  343. valid = True
  344. Case "3"
  345. valid = True
  346. Case "4"
  347. valid = True
  348. Case Else
  349. Console.WriteLine("")
  350. Console.WriteLine("Make sure you enter a number between 1 and 4 inclusive")
  351. Console.WriteLine("Please try again:" & vbNewLine)
  352. End Select
  353. Else
  354. Console.WriteLine("")
  355. Console.WriteLine("Make sure you are entering a number")
  356. Console.WriteLine("Please try again:" & vbNewLine)
  357. End If
  358. Loop
  359. If test = areapos Then
  360. points = points + 1
  361. Console.WriteLine("You got the correct answer second try and earned 1 point")
  362.  
  363. Else
  364. Console.WriteLine("You failed to guess the correct answer again" & vbNewLine)
  365. Console.WriteLine("The correct answer was " & area)
  366. End If
  367. End If
  368. Console.WriteLine()
  369. Console.WriteLine("You scored a total of " & points & " points") 'displays the total points the user earned
  370. Console.WriteLine("Press ENTER to end the program")
  371. Console.ReadLine()
  372. End Sub
  373.  
  374.  
  375. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement