Thread: why won't if()

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    208

    why won't if()

    how come this won't work??????
    Code:
    if (cor=="n"||cor=="N")
    does anyone know how I could get this same effect.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >if (cor=="n"||cor=="N")

    You can't compare strings like that. But I think you did want to compare cor with the characters n and N, which goes like this:

    if (cor == 'n' || cor== 'N')

    "n" and "m" are strings.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    208
    I declared it as a char here is the input line
    Code:
    cout<<"\n You Have Chosen To Add A New Record.\n Is This Correct: ";
      cin>>cor;
      if ( strcmp(cor,"n") == 0 || strcmp(cor,"N") == 0 )
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

Popular pages Recent additions subscribe to a feed