string countx(string sky)
{
    int count=0;
    for(int x=0;x<=sky.size();x++)
    {
         if(sky[x]=='x')
        {
            sky.erase(x);
            ++count;

        }
    }

  stringstream ins;
  string bang; // Declare an input string stream.
cout<<"count  " <<count;

ins << count;
bang = ins.str();
   sky=sky+"x^"+ bang;
  cout<<"Sky == "<<sky<<"\n";
  return sky;
}

Writing a function that will take in a string as input and then searches number of "x" in it then it writes x^count.

I am not able to figure out what is wrong ??

I have put on many cout functions .

Example input is

"x x"

It should actually return

"x^2"
but returns "x^1"

Thank You, It helped Me a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.