# Thread: VS 2010 If Else If Issue

1. ## VS 2010 If Else If Issue

So , I Have A Quiz Application ive been working on and I just ran into a problem , when it calculates your score at the bottom the % score is always correct , but if you receive over a certain % (65) then it will say you've passed that level , but when its over that amount , it says That you've failed that level , any ideas ?

Code:
```      Console.ForegroundColor = ConsoleColor.Cyan
Console.WriteLine("Level 3")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("About How Many Minutes Does It Take For Sunlight To Reach Earth ?")
two1 = Console.ReadLine.ToLower
If two1 = "8" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score13 = 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : 8")
score13 = 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("In Which U.S. State Is The Golden Gate Bridge Located In ?")
two2 = Console.ReadLine.ToLower
If two2 = "california" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score14 = score13 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : California")
score14 = score13 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Which Planet In our Solar System Spins The Fastest ?")
two3 = Console.ReadLine.ToLower
If two3 = "jupiter" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score15 = score14 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : Jupiter")
score15 = score14 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("What Is The Eastern Most Capital In The United States ?")
two4 = Console.ReadLine.ToLower
If two4 = "augusta" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score16 = score15 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : Augusta")
score16 = score15 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("What Is The Full Name Of The Person Who Painted The Famous Painting Named The Mona Lisa")
two5 = Console.ReadLine.ToLower
If two5 = "leonardo da vinci" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score17 = score16 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : Leonardo Da Vinci")
score17 = score16 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("How Many Squares Are There On A Standard Chessboard ?")
two6 = Console.ReadLine.ToLower
If two6 = "64" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score18 = score17 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : 64")
score18 = score17 + 0
End If
Console.WriteLine()
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Your Score Was:")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Percentage Form")
Console.ForegroundColor = ConsoleColor.DarkYellow
Dim scorel3 As Integer = score18 / 6 * 100
Console.WriteLine(score18 / 6 * 100)
If score18 < 65 Then
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("You Failed Level 3")
Console.ForegroundColor = ConsoleColor.Gray
Console.WriteLine("----------------------------------------------")
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("NOTE : Using Any Type Of Search Engine Or The Internet To Help You Is Cheating !")
Console.ReadLine()
End If
If score18 >= 65 Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("You Passed Level 3")
Console.ForegroundColor = ConsoleColor.Gray
Console.WriteLine("----------------------------------------------")
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("NOTE : Using Any Type Of Search Engine Or The Internet To Help You Is Cheating !")
Console.ForegroundColor = ConsoleColor.Gray
Console.WriteLine("----------------------------------------------")
End If
End If

End If
End If
End If```

2. ## Re: VS 2010 If Else If Issue

suggestion - edit your post, and put [code][/code] or [highlight=vb.net][/highlight] tags around your code. I'mnotgoingtotrytoreaditwithoutanyformattingespeciallywithnestedifs.

OR, you can set some breakpoints and step through the code to determine where the logic is wrong.

-tg

3. ## Re: VS 2010 If Else If Issue

Posting that with code tags will be move conducive to getting someone to respond.

Code:
```Console.ForegroundColor = ConsoleColor.Cyan
Console.WriteLine("Level 3")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("About How Many Minutes Does It Take For Sunlight To Reach Earth ?")
two1 = Console.ReadLine.ToLower
If two1 = "8" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score13 = 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : 8")
score13 = 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("In Which U.S. State Is The Golden Gate Bridge Located In ?")
two2 = Console.ReadLine.ToLower
If two2 = "california" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score14 = score13 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : California")
score14 = score13 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Which Planet In our Solar System Spins The Fastest ?")
two3 = Console.ReadLine.ToLower
If two3 = "jupiter" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score15 = score14 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : Jupiter")
score15 = score14 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("What Is The Eastern Most Capital In The United States ?")
two4 = Console.ReadLine.ToLower
If two4 = "augusta" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score16 = score15 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : Augusta")
score16 = score15 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("What Is The Full Name Of The Person Who Painted The Famous Painting Named The Mona Lisa")
two5 = Console.ReadLine.ToLower
If two5 = "leonardo da vinci" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score17 = score16 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : Leonardo Da Vinci")
score17 = score16 + 0
End If
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("How Many Squares Are There On A Standard Chessboard ?")
two6 = Console.ReadLine.ToLower
If two6 = "64" Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("Correct!")
score18 = score17 + 1
Else
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Incorrect")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("The Correct Answer Was : 64")
score18 = score17 + 0
End If
Console.WriteLine()
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Your Score Was:")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Percentage Form")
Console.ForegroundColor = ConsoleColor.DarkYellow
Dim scorel3 As Integer = score18 / 6 * 100
Console.WriteLine(score18 / 6 * 100)
If score18 < 65 Then
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("You Failed Level 3")
Console.ForegroundColor = ConsoleColor.Gray
Console.WriteLine("----------------------------------------------")
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("NOTE : Using Any Type Of Search Engine Or The Internet To Help You Is Cheating !")
Console.ReadLine()
End If
If score18 >= 65 Then
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("You Passed Level 3")
Console.ForegroundColor = ConsoleColor.Gray
Console.WriteLine("----------------------------------------------")
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("NOTE : Using Any Type Of Search Engine Or The Internet To Help You Is Cheating !")
Console.ForegroundColor = ConsoleColor.Gray
Console.WriteLine("----------------------------------------------")
End If```
I saw a bunch of extraneous "End If" statements when I did that. As suggested step through the code line by line.

4. ## Re: VS 2010 If Else If Issue

Any other suggestions other than debugging ?

5. ## Re: VS 2010 If Else If Issue

Yes..give up trying to program

or

You either didn't show us all the code or these are highlighted in IDE. Remove them:

End If
End If
End If
End If

6. ## Re: VS 2010 If Else If Issue

Hire a programmer? Programmers debug. It's just the way it is; it's a part of the job.

By stepping through the code (a tool used to debug) you will find your error, and probably narrow it down to one or two lines.

In addition, try breaking it down to a sequence of function calls, so you functions aren't massive splurges of random code. You can debug each function independently, ensure it's doing what it is asked to do. By limiting the amount of code in each function it makes debugging simple to almost non-existent.

7. ## Re: VS 2010 If Else If Issue

JasonPaul, I have some symapthy for you because I think some of the responses you've had in this and your other thread have been phrased much more harshly than I would like. However, outbursts like that aren't acceptable. Keep it clean.

To everyone else, don't forget we were all new once and sometimes we just didn't get it. Sometimes the weight of information coming at us was too much to cope with and we may not have immediately recognised good advice when we saw it. Sometimes it's hard to offer encouragement but it's hard to ever justify offering discouragement.

JasonPaul, some of the advice that has been given to you may not have been given in the most supportive tone but, none the less, it was good advice. You need to learn to debug if you want to progress at all. In a very real sense Debugging is programming and, unless you get your head round it you'll never be able to figure out the problems in your code. Step back from your project for a moment and actually run through some of the tutorials you were linked to in your other thread. They'll probably only take an hour or two and will improve your ability hugely, and I mean HUGELY. It may seem like a pain but you'll thank us later.

8. ## Re: VS 2010 If Else If Issue

OK...I'm sorry. Debugging is just so fundamental to programming that "Any other suggestions other than debugging" just knocked me for a loop. I apologize. If you plug that code into IDE like I did it is obvious, at least it seemed that way to me, the end ifs don't align. I didn't see how the code can run. That was my comment about the end ifs in my last post.

9. ## Re: VS 2010 If Else If Issue

Hi,

Give the kid a break guys and do yourself a favour jasonpaul2001 and delete that text in post #6. FunkyDexter beat me to it.

You have got a lot to learn but give it time and you will get there. You have made a huge mistake by using non-descriptive variable names when doing your calculations and therefore you cannot see the wood for the trees and nor can anyone else for that matter.

So, if you want to add up a quiz score in a project then use a SINGLE variable only to do the adding of that score and then create a separate PERCENTAGE variable to get the percentage to test against. Therefore those two variables could be called “TotalScore” and “PercentageTotalScore”. Easy to remember and easy to use.

However, because of your variable names you have missed the obvious! What’s wrong with this:-

vb.net Code:
`Dim scorel3 As Integer = score18 / 6 * 100Console.WriteLine(score18 / 6 * 100)If score18 < 65 Then  'etc`

Hope that helps.

Cheers,

Ian

10. ## Re: VS 2010 If Else If Issue

Here is a nice debugging tutorial:

https://www.youtube.com/watch?v=Uk-a7qVa36c

11. ## Re: VS 2010 If Else If Issue

Originally Posted by IanRyder
Hi,

Give the kid a break guys and do yourself a favour jasonpaul2001 and delete that text in post #6. FunkyDexter beat me to it.

You have got a lot to learn but give it time and you will get there. You have made a huge mistake by using non-descriptive variable names when doing your calculations and therefore you cannot see the wood for the trees and nor can anyone else for that matter.

So, if you want to add up a quiz score in a project then use a SINGLE variable only to do the adding of that score and then create a separate PERCENTAGE variable to get the percentage to test against. Therefore those two variables could be called “TotalScore” and “PercentageTotalScore”. Easy to remember and easy to use.

However, because of your variable names you have missed the obvious! What’s wrong with this:-

vb.net Code:
`Dim scorel3 As Integer = score18 / 6 * 100Console.WriteLine(score18 / 6 * 100)If score18 < 65 Then  'etc`

Hope that helps.

Cheers,

Ian
I agree with everything that IanRyder said. I'm actually surprised that this compiled at all since while noticing the error in the snippet IR provided, I also noticed that score13 was declared here yet the variable was used in the first If-block. If this code did compile, then I'm guessing that the score13 in the If-block was declared in a more general scope (eg at the class level instead of in a method). This means that you now have 2 different variables that both use the same name and could lead to confusion in the future; thus another reason to just use one variable for the score...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width