If statement runs through whether conditions are met or not

后端 未结 4 1212
北海茫月
北海茫月 2021-01-28 17:13

My if statement runs through as if the conditions have been met even when they haven\'t. I have tried moving bits of code about and even rewriting the if statement differently b

4条回答
  •  醉梦人生
    2021-01-28 17:36

    This is a bit of a side note to your question, but in this context, you may want to consider converting the answer to lowercase (or uppercase) before comparing it.

    That way, you can just use if (tolower(bob) == "no")


    Here's an example of how to do use the tolower function

    http://www.cplusplus.com/reference/cctype/tolower/

    /* tolower example */
    #include 
    #include 
    int main ()
    {
      int i=0;
      char str[]="Test String.\n";
      char c;
      while (str[i])
      {
        c=str[i];
        putchar (tolower(c));
        i++;
      }
      return 0;
    }
    

提交回复
热议问题