could you please help me with (i) and (ii)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 27SA
icon
Related questions
Question

could you please help me with (i) and (ii)

i. Convert the following switch statement into its equivalent sequence of if-else's. Include the code
in a complete C program.
switch (x)
{
case 1: printf("x equals 1\n");
break;
case 2: printf("x equals 2\n");
break;
case 3:
case 4:
case 5:
printf("x equals 3, 4 or 5\n");
break;
default: printf("x does not equal 1 to 5\n");
break;
}
Transcribed Image Text:i. Convert the following switch statement into its equivalent sequence of if-else's. Include the code in a complete C program. switch (x) { case 1: printf("x equals 1\n"); break; case 2: printf("x equals 2\n"); break; case 3: case 4: case 5: printf("x equals 3, 4 or 5\n"); break; default: printf("x does not equal 1 to 5\n"); break; }
ii. Convert the if-else sequence below into its equivalent switch construct. Include the code in a
complete C program.
const int
RAINY = 1;
const int
WINDY = 2;
const int
SUNNY = 3;
int weather;
if (weather == RAINY)
printf("Remember to take your brolly!\n");
else if (weather == WINDY)
printf("Remember to take your overcoat!\n");
else if (weather
printf("Remember to take your sunglasses!\n");
SUNNY)
==
else
printf("ERROR: unknown type of weather\n");
Transcribed Image Text:ii. Convert the if-else sequence below into its equivalent switch construct. Include the code in a complete C program. const int RAINY = 1; const int WINDY = 2; const int SUNNY = 3; int weather; if (weather == RAINY) printf("Remember to take your brolly!\n"); else if (weather == WINDY) printf("Remember to take your overcoat!\n"); else if (weather printf("Remember to take your sunglasses!\n"); SUNNY) == else printf("ERROR: unknown type of weather\n");
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,