2
userString[count] == '!' || '.' || '?'

I am trying to say if the left equals ! or .(period) or ?

Aplet123
  • 33,825
  • 1
  • 29
  • 55
Bellfrank
  • 33
  • 5
  • 5
    no, you need to do `userString[count] == '!' || userString[count] == '.' || userString[count] == '?'` – Ryan Haining Nov 17 '20 at 00:52
  • That is what I thought at first but was shying away from it because my coding class frowns upon using repetitive code, in this case userString[count] three times. I wonder if theres a library function that returns true for punctuation. thank you! – Bellfrank Nov 17 '20 at 00:53
  • 1
    There's `ispunct()` from ``, but that returns true for more punctuation characters than the three you show (such as `,` and `(` and `>`, etc). Otherwise, you could look at a search algorithm that takes a string with the acceptable characters and looks up the current character in the string — in C, you could use `strchr(".!?", userString[count])` (from `` — presumably `` in C++), or something similar. – Jonathan Leffler Nov 17 '20 at 01:06
  • Well, one can always fallback to C and try `if (strchr("!,?", userString[count]) != 0)`. Nothing wrong with using C. But only if it's used correctly, of course. – Sam Varshavchik Nov 17 '20 at 01:29
  • or `if (std::string{"!.?"}.find(userString[count]) != std::string::npos)` or c++17 forwards: `if (std::string_view{"!.?"}.find(userString[count]) != std::string_view::npos)` – Ryan Haining Nov 17 '20 at 20:23

0 Answers0