+ 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
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;
}
+ 6
BTW the switch statement is not a loop.
+ 5
Hello, š
Can you specifying your question correctly!
ā¢ Include relevant TAGS; and
Use the šSEARCH... bar!
ā¢ https://www.sololearn.com/post/10362/?ref=app
+ 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/