I used the switch statement as follows:
switch (ch){ case 'P' || 'p': goto balance; break; case 'r' || 'R': goto menu; break; default: cout<<"\t\tInvalid Choice!!"<<endl; system ("\t\tpause"); system ("cls"); goto menu; break; }
But there seems to be something wrong with the following syntax:
case 'r' || 'R'
The compiler complains about the "duplicate case value". What happened to my code?
Change it to
case 'P': case 'p': goto balance; break;
Usage is gotousually not a good idea.
goto
case 'P' || 'p': case 1, || 0, 1 . , case, 'p' || 'P', 'r' || 'R', 1, .
case 'P' || 'p':
case 1
||
0
1
case
'p' || 'P'
'r' || 'R'
case 'P' || 'p': ...
:
case 'P': case 'p': ...
, ( ) , :
switch ( std::tolower(ch) ) { case 'p': ... break; case 'r': ... break; default: ... }
#include <cctype>
|| ; 'P' || 'p' true, || . 'R' || 'r'. , case: case true:, , . :
'P' || 'p'
true
'R' || 'r'
case true:
case 'P': case 'p': menu(); // function call recommended instead of `goto` break;