For the following switch statement; a. What is output by the following code segment if month has the value 6 ? b. Assuming the code should output a single value per case, does the switch segment output the proper value(s)? If NO, what statement(s) would you add to the above switch statement so the output would always be correct? You do not have to rewrite the code segment, you may indicate the correction(s) in the existing code. int month = 6; switch (month) { case 1 : cout << "January"; case 2 : cout << "February"; case 3 : cout << "March" ; case 4 : cout << "April" ; case 5 : cout << "May" ; case 6 : cout << "June" ; case 7 : cout << "July" ; case 8 : cout << "August" ; case 9 : cout << "September" ; case 10 : cout << "October" ; case 11 : cout << "November" ; case 12 : cout << "December" ; default : cout << "Error"; }
For the following switch statement;
a. What is output by the following code segment if month has the value 6 ?
b. Assuming the code should output a single value per case, does the switch segment output the proper value(s)?
If NO, what statement(s) would you add to the above switch statement so the output would always be correct? You do not have to rewrite the code segment, you may indicate the correction(s) in the existing code.
int month = 6;
switch (month)
{
case 1 : cout << "January";
case 2 : cout << "February";
case 3 : cout << "March" ;
case 4 : cout << "April" ;
case 5 : cout << "May" ;
case 6 : cout << "June" ;
case 7 : cout << "July" ;
case 8 : cout << "August" ;
case 9 : cout << "September" ;
case 10 : cout << "October" ;
case 11 : cout << "November" ;
case 12 : cout << "December" ;
default : cout << "Error";
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps