CommonMistakes - Some Common Mistakes This list is based...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Some Common Mistakes This list is based off examples I have seen from students' code as well as examples that the TAs have seen. 1) if (ans == 'D' || 'd') Or connects two boolean expressions. For the example above, theses two expressions are a) ans == 'D' b) 'd' The first evaluates to either 0 or 1, based upon what is stored in ans. The second is a character literal. This particular character has an ascii value of 100, so the second expression ALWAYS evaluates to 100, which is ALWAYS TRUE. What should have been typed is the following: if (ans == 'D' || ans == 'd') 2) Missing brackets This is self-explanatory. When you want more than one statement in a construct, you must place braces to indicate the beginning and end of the block within the construct.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
One good technique to prevent this from being a problem is ALWAYS placing matching braces for ALL constructs before typing any code inside of the constructs, like so: while (ans != 'Q') { } 3) value = value; While this statement will do NO harm, it won't do any good
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/25/2010 for the course COMPUTER S COP3223 taught by Professor Lobo during the Spring '10 term at University of Central Florida.

Page1 / 3

CommonMistakes - Some Common Mistakes This list is based...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online