A syntax error is an error that occurs due to typing error or wrong statement that is not allowed in a language. This can be easily caught as the program does not run until this is fixed.
Logic errors are errors that happen not due to error in how the code is written, but because the code is producing an unintended or unexpected value such as a division by 0 leading to an undefined value.
Remember, syntax errors occur more for people learning a new language.
int age;cout << "age";cin >> age;if (age > 18) {cout << "You can vote in all countries with an 18 year old age for voting!";}else {cout << You cannot vote in all countries with an 18 year old age for voting.;
}
If we want the code to say when we are old enough to vote, what cases should it say when can and cannot?
int age;cout << "age";cin >> age;if (age < 18) {cout << "You can vote in all countries with an 18 year old age for voting!";}else {cout << "You cannot vote in all countries with an 18 year old age for voting.";
}