Identify and correct the errors in each of the following statements (assume that the state- ment using std::cout; is used):

a) if ( c < 7 );
cout << "c is less than 7\n";
b) if ( c => 7 )
cout << "c is equal to or greater than 7\n";

a) Error: Semicolon after the right parenthesis of the condition in the if statement. Correction: Remove the semicolon after the right parenthesis. [Note: The result of this error is that the output statement will be executed whether or not the condition in the if statement is true.] The semicolon after the right parenthesis is a null (or empty) statement—a statement that does nothing. We’ll learn more about the null statement in the next chapter.
b) Error: The relational operator =>. Correction: Change => to >=, and you may want to change “equal to or greater than” to “greater than or equal to” as well.

Computer Science & Information Technology

You might also like to view...

The ____________ uniquely identifies each row in a relational database table.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

The Callable interface (of package java.util.concurrent) declares a single method named call that allows a task to return a value.

a. call b. execute c. invoke d. None of the above.

Computer Science & Information Technology