Find the errors in the following code segments and explain how to correct them.
```
switch (n) {
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
}
```
Error: Missing break statement in the first case.
Correction: Add a break statement at the end of the first case. This is not an error if you want the statement of case 2: to execute every time the case 1: statement exe- cutes.
Computer Science & Information Technology
You might also like to view...
________ scrolling enables you to scroll through both documents at the same time using either of the two scroll bars
Fill in the blank(s) with correct word
Computer Science & Information Technology
The SUMIFS function adds values in multiple ranges that meet multiple conditions or criteria
Indicate whether the statement is true or false
Computer Science & Information Technology