Given the following seqment of code containing a group of
nested if instructions: y = 9; if ((x==3) || (x == 5)) y++;
else if (x == 2) y *= 2; else if (x == 4 ) y-= 7; else y =
8; Enter a segment of code (without any IF statements) that
does exectly the same thing using the switch structure.
Answer Posted / isha
y=9;
switch(x)
{
case 2:y*=2;
break;
case 3:
case 5: y++;
break;
case 4:y-=7;
break;
default:y=8;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
How do we implement inheritance in c++?
What are multiple inheritances (virtual inheritance)?
What does it mean to declare a destructor as static?
Does c++ support multilevel and multiple inheritances?
What is a tree in c++?
What is ctime c++?
Can I create my own functions in c++?
What does obj stand for?
What is the difference between mutex and binary semaphore?
Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?
Explain rethrowing exceptions with an example?
why is iostream::eof inside a loop condition considered wrong?
what is upcasting in C++?
How do I get good at c++ programming?
How the delete operator differs from the delete[]operator?