Question

Re-write the following if statement structure as a SWITCH/CASE statement in C++ and Pseudocode:       X...

Re-write the following if statement structure as a SWITCH/CASE statement in C++ and Pseudocode:

      X ← 1

      A ← 3
      IF (a is equal to 1) THEN
         x ← x + 5
      ELSE IF (a is equal to 2) THEN
         x ← x + 10
      ELSE IF (a is equal to 3) THEN
         x ← x + 15
      ELSE IF (a is equal to 4) THEN
         x ← x + 20
      ELSE x ← x + 100

      ENDIF

PRINT("x = " + x);

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Pseudocode:
--------------
X ← 1
A ← 3
SWITCH(A)
    CASE 1:
        x ← x + 5
        BREAK
    CASE 2:
        x ← x + 10
        BREAK
    CASE 3:
        x ← x + 15
        BREAK
    CASE 4:
         x ← x + 20
         BREAK
    DEFAULT:
        x ← x + 100
ENDSWITCH
PRINT("x = " + x);

================================================

C++ code:
-----------
X = 1
A = 3
switch(A){
    case 1:
        x = x + 5;
        break;
    case 2:
        x = x + 10;
        break;
    case 3:
        x = x + 15;
        break;
    case 4:
         x = x + 20;
         break;
    default:
        x = x + 100;
}
cout<<"x = "<<x<<endl;
Add a comment
Know the answer?
Add Answer to:
Re-write the following if statement structure as a SWITCH/CASE statement in C++ and Pseudocode:       X...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT