+ 1

Is there any use of default statement un switch loop????

Im a begineer so your answer should be easily understood..... Share your answer/views as fast as soon

14th Aug 2019, 12:50 PM
Pragya Das
4 Answers
+ 7
I use it commonly when I need to handle the input. Of course it can use on more rather than just handle the input. For example: I want to make a simple calculator, so I need 2 numbers and a character as operator. The valid operator for this porgram is +-*/ , but what if the user input 4 & 4? & isn't the valid operator for it. So we can do the following: switch(operator) { case '+': a+b: break; case '-': a-b; break; case '*': a*b; break; case '/': a/b; break; default: cout << "Invalid operator"; break; }
14th Aug 2019, 1:09 PM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 6
BTW the switch statement is not a loop.
14th Aug 2019, 2:36 PM
Sonic
Sonic - avatar
+ 5
Hello, šŸ˜Š Can you specifying your question correctly! ā€¢ Include relevant TAGS; and Use the šŸ”SEARCH... bar! ā€¢ https://www.sololearn.com/post/10362/?ref=app
14th Aug 2019, 3:34 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 5
Pragya Das Keep going with C++ tutorial and read the COMMENTS in the lessons, you can find a great examples and explanations. ā€¢ The default Case In a switch statement, the optional 'default' case can be used to perform a task when none of the cases is determined to be true. https://www.sololearn.com/learn/CPlusPlus/1618/
14th Aug 2019, 3:43 PM
Danijel Ivanović
Danijel Ivanović - avatar