Identify and correct the errors in each of the following
Identify and correct the errors in each of the following:
- while ( c <= 5 )
{
product *= c;
++c;
- cin <<value;
- if ( gender == 1 )
cout << "Woman" << endl;
else;
cout << "Man" <<
endl;
Solution
- Error: Missing the closing right brace of the while body.
Correction: Add closing right brace after the statement ++c;
- Error: Used stream insertion instead of stream extraction.
Correction: Change << to >>.
- Error: Semicolon after else results is a logical error. The second
output statement will always be executed.
Correction: Remove the semicolon after else.
If You Enjoyed This, Take 5 Seconds To Share It
0 Questions:
Post a Comment