title: PigLatin C++ function
body: <p>This code is giving me a lot of strange errors. For whatever reason, the "newstring" function is not running. I think it may have something to do with the fact that it is part of a cout statement, because if I remember correctly, it does not give the same error if I call the function independently of the cout statement. The program requires a string function, but the new function is not running for some reason. Could anyone take a look at the code? </p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;string&gt;
  
      using namespace std;
  
      void newstring(string);
      bool isVowel(char ch);
      string rotate(string pStr);
      string pigLatinString(string pStr);
  
      int main()
      {
          string str;
  
          cout &lt;&lt; "Enter a sentence to be translated to Pig Latin: ";
          getline(cin, str);
          cout &lt;&lt; endl;
  
          cout &lt;&lt; "The pig Latin form of " &lt;&lt; str &lt;&lt; " is: " &lt;&lt; newstring(str);
  
          system("PAUSE");
          return 0;
  
      }
  
      bool isVowel(char ch)
      {
          switch(ch)
          {
              case 'A':
              case 'E':
              case 'I':
              case 'O':
              case 'U':
              case 'Y':
              case 'a':
              case 'e':
              case 'i':
              case 'o':
              case 'u':
              case 'y':
                  return true;
              default: 
                  return false;
          }
      }
      string rotate(string pStr)
      {
          string::size_type len = pStr.length();
          string rStr;
          rStr = pStr.substr(1, len - 1) + pStr[0];
          return rStr;
      }       
      string pigLatinString(string pStr)
      {
          string :: size_type len;
          bool foundVowel;
          if (isVowel(pStr[0]))
              pStr = pStr + "-way";
          else 
              {
                  pStr = pStr + '-';
                  pStr = rotate(pStr);
                  len = pStr.length();
                  foundVowel = false;
  
              for ( int counter = 1; counter &lt; len - 1; counter++)
                  {
                        if (isVowel(pStr[0]))
                  {
                      foundVowel = true;
                      break;
                  }
                  else 
                      pStr = rotate(pStr);
  
                  if (!foundVowel)
                      pStr = pStr.substr(1, len) + "-way";
                      else    
                      pStr = pStr + "ay";
                  }
                  return pStr;
              }
      }
  
      string newstring(string sentence)
      {   
          string newsentence, currentword;
  
          for (int i = 0; i &lt; sentence.length(); i++)
          {
              if (sentence[i]==' ')
              {
                  pigLatinString(currentword)+" ";
                  currentword.clear();
              }
              else
              {
                  currentword+=sentence[i];
              }
          }
          return newsentence;
      }
  </code></pre>