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." << endl; break; case 1: cout << "Win." << endl; break; case 2: cout << "Lose." << endl; break; } b) switch (digit / 4) { case 0, case 1: cout << "low." << endl; break; case 1, case 2: cout << "middle." << endl; break; case 3: cout << "high." << endl; } 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; }
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Question:
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." << endl;
break;
case 1:
cout << "Win." << endl;
break;
case 2:
cout << "Lose." << endl;
break;
}
b) switch (digit / 4) {
case 0,
case 1:
cout << "low." << endl;
break;
case 1,
case 2:
cout << "middle." << endl;
break;
case 3:
cout << "high." << endl;
}
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;
}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









