why won't if()

This is a discussion on why won't if() within the C++ Programming forums, part of the General Programming Boards category; how come this won't work?????? Code: if (cor=="n"||cor=="N") does anyone know how I could get this same effect....

  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,386
    >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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21