Overclock.net banner

1 - 9 of 9 Posts

·
Registered
Joined
·
425 Posts
Discussion Starter #1
I cannot get this to compile and have been trying to figure it out for almost an hour... its driving me nuts... please tell me what im doing wrong

Code:

Code:
 switch (choice)
 {
        case 'y' or 'Y':
             again = 1;
             break; 
        case 'n' or 'N':
             again = 0;
             break;
        default:
                oops=1;
                cout << "Please enter a valid option" <<endl;
                break;
 }
 

·
Registered
Joined
·
425 Posts
Discussion Starter #3
Quote:


Originally Posted by Jacka
View Post

Code:
Code:
switch (choice){
        case 'y':
        case 'Y':
             again = 1;
             break; 
        case 'n':
        case 'N':
             again = 0;
             break;
        default:
                oops=1;
                cout << "Please enter a valid option" <<endl;
                break;
 }
wow im speshul! thanks lol rep+ i cant beleive i couldnt find that anywhere... i guess i was looking in the wrong places....
 

·
Registered
Joined
·
231 Posts
Just so you know this would be the correct use of or.. personally I'd just use
choice = toupper(choice); Then only need to use caps, it helps save typing when you have a bunch of switch statements.

switch (choice)
{
case 'y' || 'Y':
again = 1;
break;
case 'n' || 'N':
again = 0;
break;
default:
oops=1;
cout << "Please enter a valid option" <<endl;
break;
}
 

·
Registered
Joined
·
152 Posts
I think he's just saying double pipe || is the proper "or" operator such as in if statements.

And I also agree that converting everything to a common case is easier than having multiple statements for each character.
 

·
Registered
Joined
·
425 Posts
Discussion Starter #7
Quote:

Originally Posted by orangeTheory View Post
I think he's just saying double pipe || is the proper "or" operator such as in if statements.

And I also agree that converting everything to a common case is easier than having multiple statements for each character.
And how would you go about doing that?
 

·
Registered
Joined
·
152 Posts
Just like SevasTra said, toupper( char ); or tolower( char );

So before the switch block, use that to convert whatever input the user gives and then you don't need to worry about the case you're converting away from.
 

·
Registered
Joined
·
551 Posts
Quote:

Originally Posted by orangeTheory View Post
I think he's just saying double pipe || is the proper "or" operator such as in if statements.

And I also agree that converting everything to a common case is easier than having multiple statements for each character.
This doesn't change the fact that using a || like that won't compile. You cannot do it, the fact that || is the or operator in C is beside the point.
 
1 - 9 of 9 Posts
Top