fork download
  1. #include <iostream> // for cout and cin
  2. #include <string> // for string commands
  3. using namespace std;
  4.  
  5. bool hasDoubleChars(const string &str) {
  6. for (size_t i = 1; i < str.size(); ++i) {
  7. if (str[i] == str[i-1]) {
  8. return true;
  9. }
  10. }
  11. return false;
  12. }
  13.  
  14. int main() {
  15. string str;
  16.  
  17. cout << "Welcome to the DoubleChecker(TM) word checker" << endl;
  18. cout << "=============================================" << endl;
  19. //cout << "Enter a word to check: " << endl;
  20. while (cin >> str) {
  21. if (hasDoubleChars(str)) {
  22. cout << "There are double characters in the word " << str << ".";
  23. } else {
  24. cout << "There are no double characters in the word " << str << ".";
  25. }
  26. cout << endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 4392KB
stdin
supercalifragilisticexpialidocious
emphasis
different
mississippi
formatting
stdout
Welcome to the DoubleChecker(TM) word checker
=============================================
There are no double characters in the word supercalifragilisticexpialidocious.
There are no double characters in the word emphasis.
There are double characters in the word different.
There are double characters in the word mississippi.
There are double characters in the word formatting.