title: SPOJ question - WHat is going wrong here?
body: <p>I was answering this spoj question:
  <a href="http://www.spoj.pl/problems/JAVAC/" rel="nofollow">http://www.spoj.pl/problems/JAVAC/</a></p>
  
  <p>I coded the submission in C++. I am pasting it below. The submission consistently gives wrong answer. I cannot find a test case for which it will fail. Can anyone help me out ?</p>
  
  <p>Thanks very much.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;algorithm&gt;
  
  using namespace std;
  
  char *ans;
  
  bool iscapital(char c)
  {
    if(c &gt;='A' &amp;&amp; c &lt;='Z')
      return true;
    else
      return false;
  }
  
  string translate(string current)
  { 
    ans = new char[2*current.length() + 1];
    int jflag = 0, cflag = 0,j = 0, i = 0;
  
    if(iscapital(current[0]))
    {
      return "Error!";
    }
  
    while(i &lt; current.length())
    {
      if(current[i] !='_')
      {
        if(!(current[i] &gt;= 'A' &amp;&amp; current[i] &lt;= 'Z'))
        {
      ans[j] = current[i];
      i++;
      j++;
        }
      }
  
      if(current[i] == '_')
      {
        if(jflag == 1)
      return "Error!";
  
        cflag = 1;
        i++;
        if(i &lt; current.length())
        {
      //convert to capital
      if(iscapital(current[i]))
        return "Error!";
  
      ans[j] = (char)((int)current[i] - 32);
      i++;
      j++;
        }
      }
  
      if(iscapital(current[i]))
      {
        if(cflag == 1)
      return "Error!";
  
        jflag = 1;
  
        ans[j] = '_';
        j++;
        ans[j] = (char)((int)current[i] + 32);
        j++;
        i++;
      }
    }
    ans[j] = '\0';
    string ret = ans;
    return ret;
  }
  
  
  
  int main()
  {
  
    string current;
  
    while(cin&gt;&gt;current)
    {
      cout&lt;&lt;translate(current)&lt;&lt;endl;
    }
    return 0;
  }
  </code></pre>