{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

tutorial03.pptx - CSCI 1120 Introduction to Computing Using...

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

View Full Document Right Arrow Icon
CSCI 1120 Introduction to Computing Using C++ Tutorial 3 LI, Le SHB 1013 [email protected] 1
Background image of page 1

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

View Full Document Right Arrow Icon
Outline Why debugging? General debug procedure Debug with IDE (Visual Studio 2015) 2
Background image of page 2
Syntax error… Your program won’t even compile… Missing semicolon ; Unbalanced parenthesis () {} Missing include statements… (#include <xyz>) Logical error Your program can be compiled, but does not work a s expected… What’s going on? Types of Error 3
Background image of page 3

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

View Full Document Right Arrow Icon
1. Locate the bug What we are going to talk about… 2. Fix it! This part is up to you… I have written a "buggy" program, what should I do? 4
Background image of page 4
Debugging is a methodical process of finding a nd reducing the number of bugs , or defects , in a computer program or a piece of electronic h ardware, thus making it behave as expected . Debugging 5
Background image of page 5

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

View Full Document Right Arrow Icon
Make sure it is indented!!! Before Debugging Your Program 6
Background image of page 6
Indent code according to program structure Inner structure => indent deeper Spaces : usually multiple of 2 / 4 Tabs: e.g. Visual Studio Use the same type of indentation throughout the whole program Don’t mix spaces and tabs Indentation int main() { int x = 0; while (x != -1) { cin >> x; if ((x % 2) == 0) { cout << x; } } return 0; } 7
Background image of page 7

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

View Full Document Right Arrow Icon
Indentation is Important There is an error in both code below Which one is easier to spot? int main() { int x; cin >> x; while (x > 0) { if ((x % 2) == 0){ cout << x; x--; } } int main() { int x; cin >> x; while (x > 0) { if ((x % 2) == 0){ cout << x; x--; } } Easier to recognize Unbalanced parenthesis 8
Background image of page 8
Auto Correction in VS Express 2015 VS Express 2015 can auto correct indentation EDIT -> Advanced -> Format Document 9
Background image of page 9

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

View Full Document Right Arrow Icon
Auto Correction in VS Express 2015 VS Express 2015 can auto correct indentation EDIT -> Advanced -> Format Document 10
Background image of page 10
Outline Why debugging?
Background image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}