Code:switch(c) case 'a': cout <<"hello"; case 'b': cout << "hello";
if there anyway I can shorten the code since both case a and b do the exact same thing?
Code:switch(c) case 'a': cout <<"hello"; case 'b': cout << "hello";
if there anyway I can shorten the code since both case a and b do the exact same thing?
Switch cases fall through unless there is a break statement. For example,
will print "hello" is c is a or b, and print "bye" if c is 'c'.Code:switch(c) { case 'a': case 'b': cout <<"hello"; break; case 'c': cout << "bye"; break; }
You could also use an "if" statement.