In this video, we'll talk about logic errors and why they can happen.
Logic errors, or errors or bugs in your code
that cause your program to run incorrectly.
Logic errors are mistakes made by a programmer.
Sometimes the mistakes are careless of the time.
Some mistakes are because the programmers have incomplete or incorrect information.
Other times mistakes occur when one programmer modifies another programmer's code
to fix or add something, and they introduce an error as they do this.
There are many, many causes for logic errors.
It doesn't matter what the cause is though, they need to be corrected.
We need to test our code and debug it to find incorrect errors.
Suppose we have a program that determines if a person can vote in an election
and you must be 18 years old or older to vote.
We haven't talked about if statements yet in this class.
But they're very intuitive and I'm sure you'll follow this little piece of code.
First, we test to see if the age is greater than 18.
If it is, then we execute the code that's inside those curly braces.
Do you see the error.
It�s pretty easy to see it here because the code is isolated,
and I told you there was an error.
However, in reality, there's much more code typically involved.
In this may just be a small part of a much larger program.
The problem with this code is that the test conditions should be greater than
or equal to 18 or greater than 17,
either one will work.
As it's written now, 18 year old would not be able to vote.
We'll talk about testing throughout the course in the context of
learning c++ and best practices.
Well, that wraps up this section.
Next, you can take the section quiz and attempt the challenge exercise and see how you do.
I'm sure you'll do great. If you have any questions, please post them to the course forum.