Question: State whether the following are valid switch statements. If not, explain why. Assume that n and digit are int variables. a) switch (n

State whether the following are valid switch statements. If not, explain why. Assume that n and digit are int variables.

a) switch (n <= 2) { case 0: cout << "Draw." << end1; break; case 1: cout << "Win." << end1; break; case 2: cout << "Lose." << end1; break; }

b) switch (digit / 4) { case 0, case 1: cout << "low." << end1; break; case 1, case 2: cout << "middle." << end1; break; case 3: cout << "high." << end1; }

c) switch (n % 6) { case 1: case 2: case 3: case 4: case 5: cout << n; break; case 0: cout << end1; break; }

d) switch (n % 10) { case 2: case 4: case 6: case 8: cout << "Even"; break; case 1: case 3: case 5: case 7: cout << "Odd"; break; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!