• 0

[C++] Error checking


Question

I wanna check if a character (college) is either T, C, E, O , G or J. return 1 else return 0

if(toupper(college) ==('T' || 'E' || 'O' || 'G' || 'J'))

it doesn't work though.. any help?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You should probably switch off of those, otherwise, you'll have a sloppy if statement.

switch( toupper(college) )
{
    case 'T':
    case 'E':
    case 'O':
    case 'G':
    case 'J':
        return 1;
    default:
        return 0;
}

To do compound if statements you'd need to do this:

if( toupper(college) == 'T' ||
    toupper(college) == 'E' ||
    toupper(college) == 'O' ||
    toupper(college) == 'G' ||
    toupper(college) == 'J' )
    return 1;
else
    return 0;

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.