Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Dim valid As Boolean
- Sub Main()
- Dim test As Integer
- Dim areapos As Integer
- Dim area As Integer
- Userpass()
- shapechoice(test)
- guessoptions(test, areapos, area)
- points(areapos, test, area)
- End Sub
- Sub Userpass()
- Dim username As String
- Dim password As String
- Dim character As Char
- Dim stepper As Integer
- Dim digit As Boolean
- 'Do Until valid = True
- ' test = rand.Next(15)
- ' Console.WriteLine(test)
- ' Console.ReadLine()
- 'Loop
- Console.WriteLine("Welcome to the area trainer!" & vbNewLine)
- Console.WriteLine("Please enter your username to start:")
- username = Console.ReadLine 'allows input of username
- Do Until valid = True 'loops until a password of appropriate strength is entered
- valid = False
- Console.WriteLine("Please enter your password:")
- Console.WriteLine("(It must be atleast 7 digits long and contain a number)")
- password = Console.ReadLine
- If Len(password) >= 7 Then 'makes sure the password entered is atleast 7 digits long
- stepper = 1
- character = Mid(password, stepper, 1)
- If Char.IsDigit(character) Then 'makes sure the password entered contains a number
- digit = True
- End If
- If digit = True Then
- valid = True
- Else
- Console.WriteLine("Make sure your password contains a number" & vbNewLine)
- End If
- Else
- Console.WriteLine("Your password was not atleast 7 digits long,")
- Console.WriteLine("Please try again." & vbNewLine)
- Console.WriteLine("PRESS ENTER TO CONTINUE")
- Console.ReadLine()
- Console.Clear()
- End If
- Loop
- Console.Clear()
- Console.WriteLine("Logged in" & vbNewLine)
- End Sub
- Sub shapechoice(ByRef test As Integer)
- Dim choice As Char
- valid = False
- Do Until valid = True 'loops until a valid number is entered as a choice
- Console.WriteLine("Now enter the number of the shape you want to train with:")
- Console.WriteLine("1: Square")
- Console.WriteLine("2: Circle")
- Console.WriteLine("3: Triangle")
- choice = Console.ReadLine
- If Char.IsDigit(choice) Then 'checks that the userinput is a number
- test = Left(choice, 1) 'converts the char to an integer
- 'Console.WriteLine(test)
- Select Case test 'checks that the number is 1, 2 or 3
- Case "1"
- valid = True
- Case "2"
- valid = True
- Case "3"
- valid = True
- Case Else
- Console.WriteLine("")
- Console.WriteLine("Make sure you enter a number between 1 and 3 inclusive")
- Console.WriteLine("Please try again:" & vbNewLine)
- End Select
- Else
- Console.WriteLine("")
- Console.WriteLine("Make sure you are entering a number")
- Console.WriteLine("Please try again:" & vbNewLine)
- End If
- Loop
- End Sub
- Sub guessoptions(ByVal test As Integer, ByRef areapos As Integer, ByRef area As Integer)
- Dim rand As New Random
- Dim position As Integer
- Dim length, width As Integer
- Dim option1, option2, option3 As Integer
- Select Case test
- Case "1" 'all the code for the square
- Do Until length > 0 'makes sure length is not 0
- length = rand.Next(15)
- Loop
- Do Until width > 0 'makes sure width is not 0
- width = rand.Next(15)
- Loop
- area = length * width 'calculates area of the square
- 'Console.WriteLine(area)
- valid = False
- Do Until valid = True 'generates each incorrect answer and makes sure they are all different from each other and the area
- option1 = rand.Next(197)
- If option1 <> area Then
- valid = True
- End If
- Loop
- valid = False
- Do Until valid = True
- option2 = rand.Next(197)
- If option2 <> area Then
- If option2 <> option1 Then
- valid = True
- End If
- End If
- Loop
- valid = False
- Do Until valid = True
- option3 = rand.Next(197)
- If option3 <> area Then
- If option3 <> option1 Then
- If option3 <> option2 Then
- valid = True
- End If
- End If
- End If
- Loop
- Console.WriteLine("The length of the square is: " & length & "cm and the width of the square is: " & width & "cm")
- Console.WriteLine("Input the number for the answer that you think is the correct area")
- position = rand.Next(4) 'generates a random number to put the correct answer in a random position
- Select Case position 'writes out the list of 4 possible answers
- Case "0"
- Console.WriteLine("1. " & area)
- Console.WriteLine("2. " & option1)
- Console.WriteLine("3. " & option2)
- Console.WriteLine("4. " & option3)
- areapos = 1
- Case "1"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & area)
- Console.WriteLine("3. " & option2)
- Console.WriteLine("4. " & option3)
- areapos = 2
- Case "2"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & option2)
- Console.WriteLine("3. " & area)
- Console.WriteLine("4. " & option3)
- areapos = 3
- Case "3"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & option2)
- Console.WriteLine("3. " & option3)
- Console.WriteLine("4. " & area)
- areapos = 4
- End Select
- Case "2"
- Do Until length > 0 'makes sure length is not 0
- length = rand.Next(15)
- Loop
- area = 3.14 * (length * length) 'works out the area of the circle
- 'Console.WriteLine(area)
- valid = False
- Do Until valid = True 'generates each incorrect answer and makes sure they are all different from each other and the area
- option1 = rand.Next(616)
- If option1 <> area Then
- valid = True
- End If
- Loop
- valid = False
- Do Until valid = True
- option2 = rand.Next(616)
- If option2 <> area Then
- If option2 <> option1 Then
- valid = True
- End If
- End If
- Loop
- valid = False
- Do Until valid = True
- option3 = rand.Next(616)
- If option3 <> area Then
- If option3 <> option2 Then
- If option3 <> option1 Then
- valid = True
- End If
- End If
- End If
- Loop
- Console.WriteLine("The radius of the circle is " & length & "cm")
- Console.WriteLine("Assuming pi is 3.14 and all answers are rounded to the nearest integer")
- Console.WriteLine("Input the number for the answer that you think is the correct area")
- position = rand.Next(4) 'generates a random number to put the correct answer in a random position
- Select Case position 'writes out the list of 4 possible answers
- Case "0"
- Console.WriteLine("1. " & area)
- Console.WriteLine("2. " & option1)
- Console.WriteLine("3. " & option2)
- Console.WriteLine("4. " & option3)
- areapos = 1
- Case "1"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & area)
- Console.WriteLine("3. " & option2)
- Console.WriteLine("4. " & option3)
- areapos = 2
- Case "2"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & option2)
- Console.WriteLine("3. " & area)
- Console.WriteLine("4. " & option3)
- areapos = 3
- Case "3"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & option2)
- Console.WriteLine("3. " & option3)
- Console.WriteLine("4. " & area)
- areapos = 4
- End Select
- Case "3"
- Do Until length > 0 'makes sure length is 0
- length = rand.Next(15)
- Loop
- Do Until width > 0 'makes sure width is 0
- width = rand.Next(15)
- Loop
- area = (length / 2) * width 'works out the area of the triangle
- 'Console.WriteLine(area)
- valid = False
- Do Until valid = True 'generates each incorrect answer and makes sure they are all different from each other and the area
- option1 = rand.Next(99)
- If option1 <> area Then
- valid = True
- End If
- Loop
- valid = False
- Do Until valid = True
- option2 = rand.Next(99)
- If option2 <> area Then
- If option2 <> option1 Then
- valid = True
- End If
- End If
- Loop
- valid = False
- Do Until valid = True
- option3 = rand.Next(99)
- If option3 <> area Then
- If option3 <> option2 Then
- If option3 <> option1 Then
- valid = True
- End If
- End If
- End If
- Loop
- Console.WriteLine("The base of the triangle is " & length & "cm and the height of the triangle is " & width & "cm")
- Console.WriteLine("Input the number for the answer that you think is the correct area")
- position = rand.Next(4) 'generates a random number to put the correct answer in a random position
- Select Case position 'writes out the list of 4 possible answers
- Case "0"
- Console.WriteLine("1. " & area)
- Console.WriteLine("2. " & option1)
- Console.WriteLine("3. " & option2)
- Console.WriteLine("4. " & option3)
- areapos = 1
- Case "1"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & area)
- Console.WriteLine("3. " & option2)
- Console.WriteLine("4. " & option3)
- areapos = 2
- Case "2"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & option2)
- Console.WriteLine("3. " & area)
- Console.WriteLine("4. " & option3)
- areapos = 3
- Case "3"
- Console.WriteLine("1. " & option1)
- Console.WriteLine("2. " & option2)
- Console.WriteLine("3. " & option3)
- Console.WriteLine("4. " & area)
- areapos = 4
- End Select
- End Select
- End Sub
- Sub points(ByVal areapos As Integer, ByRef test As Integer, ByVal area As Integer)
- Dim guess As Char
- Dim points As Integer
- points = 0
- valid = False
- Do Until valid = True 'loops until a valid guess is entered
- guess = Console.ReadLine
- If Char.IsDigit(guess) Then 'make sure the guess is a number
- test = Left(guess, 1) 'converts the char to an integer
- Select Case test 'makes sure the guess is 1, 2, 3 or 4
- Case "1"
- valid = True
- Case "2"
- valid = True
- Case "3"
- valid = True
- Case "4"
- valid = True
- Case Else
- Console.WriteLine("")
- Console.WriteLine("Make sure you enter a number between 1 and 4 inclusive")
- Console.WriteLine("Please try again:" & vbNewLine)
- End Select
- Else
- Console.WriteLine("")
- Console.WriteLine("Make sure you are entering a number")
- Console.WriteLine("Please try again:" & vbNewLine)
- End If
- Loop
- 'Console.WriteLine("valid")
- If test = areapos Then 'checks if the guess is equal to the position of the correct answer
- points = points + 2 'adds to points for a first time guess
- Console.WriteLine("You guessed the correct answer and earned 2 points")
- Else
- Console.WriteLine("You entered an incorrect answer, try again") 'allows a second guess if the first was wrong
- valid = False
- Do Until valid = True 'loops until a valid guess is entered
- guess = Console.ReadLine
- If Char.IsDigit(guess) Then 'makes sure the guess is a number
- test = Left(guess, 1) 'converts the char to an integer
- Select Case test 'makes sure the guess is 1, 2, 3 or 4
- Case "1"
- valid = True
- Case "2"
- valid = True
- Case "3"
- valid = True
- Case "4"
- valid = True
- Case Else
- Console.WriteLine("")
- Console.WriteLine("Make sure you enter a number between 1 and 4 inclusive")
- Console.WriteLine("Please try again:" & vbNewLine)
- End Select
- Else
- Console.WriteLine("")
- Console.WriteLine("Make sure you are entering a number")
- Console.WriteLine("Please try again:" & vbNewLine)
- End If
- Loop
- If test = areapos Then
- points = points + 1
- Console.WriteLine("You got the correct answer second try and earned 1 point")
- Else
- Console.WriteLine("You failed to guess the correct answer again" & vbNewLine)
- Console.WriteLine("The correct answer was " & area)
- End If
- End If
- Console.WriteLine()
- Console.WriteLine("You scored a total of " & points & " points") 'displays the total points the user earned
- Console.WriteLine("Press ENTER to end the program")
- Console.ReadLine()
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement