Mynotoar
Active member
Hey! I should start with a clarification: I'm new to the forums, and I'm also very new to VB. I started studying it at A-level Computing nearly three weeks ago. So please bear in mind that I'm nowhere near an expert and may need simple explanations . Also, I'm working with a console application, and not a... whatever the other thing is called!
So what I'm trying to do is to create a quiz where you can answer the questions in any order. Say I have a five-question quiz. First I declare five values that are constants, they're the answers, and they're what'll be referred to. So I'll call them "red", "orange", "green", "blue" and "black". The program I want to write would then have you enter at least five variables, one at a time. If the variable matches the constant, so you type in "orange" (we'll assume everything is forced to lowercase so there are no case problems,) then it determines whether "orange" matches any of the five constants. If it does, it tallies up a value called "score" which would be totalled once you've filled all five answer slots or something like that.
If it was in order, I'd understand how to do it just fine. Here's what my code would look like - so you get an idea of the things I know, too.
So this is just asking you to enter the variable, checking the variable (forced into lowercase) matches the constant, and if it does then the "score" value goes up, and is tallied at the end.
That's fine. But how on Earth could I do it out of order? In my head, I'm thinking that I'd have to say for every line that you input something like "Does it match constant1, does it match constant2, does it match constant3..." etc., and that would be tedious if I were doing 118 questions instead of 5. Is there a more efficient way? And if there isn't, how do I do it the first way, because I can't work that out either? I tried using "or" to say "If variable1 = constant1 OR constant2 OR constant3" but that doesn't work, it thinks I'm trying to convert the variable type or something silly.
Can anyone offer any help/advice? Input would be greatly and warmly appreciated <3.
So what I'm trying to do is to create a quiz where you can answer the questions in any order. Say I have a five-question quiz. First I declare five values that are constants, they're the answers, and they're what'll be referred to. So I'll call them "red", "orange", "green", "blue" and "black". The program I want to write would then have you enter at least five variables, one at a time. If the variable matches the constant, so you type in "orange" (we'll assume everything is forced to lowercase so there are no case problems,) then it determines whether "orange" matches any of the five constants. If it does, it tallies up a value called "score" which would be totalled once you've filled all five answer slots or something like that.
If it was in order, I'd understand how to do it just fine. Here's what my code would look like - so you get an idea of the things I know, too.
VB.NET:
Module Module1
Sub Main()
Dim variable1, variable2, variable3, variable4, variable5 As String
Dim constant1, constant2, constant3, constant4, constant5 As String
Dim score As Integer
constant1 = "red"
constant2 = "orange"
constant3 = "green"
constant4 = "blue"
constant5 = "black"
score = 0
'I'm just clearing it in case I want to include a Do loop later.
Console.WriteLine("Enter a colour that starts with r.")
variable1 = Console.ReadLine
If LCase(variable1) = constant1 Then
score = score + 1
'The answer is correct, the score is now 1.
Else
score = score
End If
Console.WriteLine("Enter a colour that starts with o.")
variable2 = Console.ReadLine
If LCase(variable2) = constant2 Then
score = score + 1
Else
score = score
End If
Console.WriteLine("Enter a colour that starts with g.")
variable3 = Console.ReadLine
If LCase(variable3) = constant3 Then
score = score + 1
Else
score = score
End If
Console.WriteLine("Enter a colour that starts with b.")
variable4 = Console.ReadLine
If LCase(variable4) = constant4 Then
score = score + 1
Else
score = score
End If
Console.WriteLine("Enter a colour that starts with b.")
variable5 = Console.ReadLine
If LCase(variable5) = constant5 Then
score = score + 1
Else
score = score
End If
Console.WriteLine("You got " & score & "/5.")
Console.ReadLine()
End Sub
End Module
So this is just asking you to enter the variable, checking the variable (forced into lowercase) matches the constant, and if it does then the "score" value goes up, and is tallied at the end.
That's fine. But how on Earth could I do it out of order? In my head, I'm thinking that I'd have to say for every line that you input something like "Does it match constant1, does it match constant2, does it match constant3..." etc., and that would be tedious if I were doing 118 questions instead of 5. Is there a more efficient way? And if there isn't, how do I do it the first way, because I can't work that out either? I tried using "or" to say "If variable1 = constant1 OR constant2 OR constant3" but that doesn't work, it thinks I'm trying to convert the variable type or something silly.
Can anyone offer any help/advice? Input would be greatly and warmly appreciated <3.