Chapter 1 Part 2
Chapter 1 Part 2
I N T E R AC T I V I T Y
The interaction process between the user and the program
3 a. Indentation
Indentation helps in making the structure of the program
clearer and easier to read. A statement within a statement
should be indented to show the user which statements are
subordinated of the other.
In C++, particularly, if‐else, while and do‐while statements
should be indented. Embedded braces { } are also indented
to make it easier to find the matching pairs.
CSC126 FUNDAMENTALS OF ALGORITHMS AND COMPUTER PROBLEM SOLVING 7
3
a. Comments
Some explanatory notes or comments (sometimes
referred to as internal documentation) should be place in
a. Comments
Some explanatory notes or comments (sometimes
referred to as internal documentation) should be place in
Errors
1.RUN-TIME 3.LOGIC
Errors Errors
Explanation:
Attempting to divide by zero in the above statement causes a
run‐time error such as “Floating point division by error” or
divide‐error exception”. The method for detecting errors
after a program has been executed is called debugging process.
A debugger program is available in C++ for detecting errors
while a program is being executed.
Explanation:
i. Invalid use of backslash (/) in line 6
ii. Missing semicolon (;) in line 6
iii.Keyword cout is misspelled in line 7
iv. Invalid use of insertion symbol (>>) in line 7
v. Missing a closing quote (“) in line 7
Example :
Example:
3
line 1
ii. Attempting to divide by zero in line 3
iii. Missing numerical output in line 4
iv. Taking the square root of a negative number in line 5