Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how do i add to this program in C++ in order if the user entered 3 x\'s in a row

ID: 3567140 • Letter: H

Question

how do i add to this program in C++ in order if the user entered 3 x's in a row it would say There is at least one triple X in this data.

please use c++ and my code that is attached for full credit.

this is my code till now

using namespace std; int main(){

int number = 9;

vector userString(number);

string str;

for (int i = 0; i < 9; i++){

cout << "Please enter an X or O for position " << i << ": ";

cin>>str;

if ((str== "x") || (str == "o")){

userString.at(i)=str;

}

else{

cout << "Please follow the directions!" << endl;

i=i-1;

}

}

for (int y = 8; y >= 0; y--){

cout << userString.at(y);

}

cout << endl;

return 0;

}

Explanation / Answer

Add the following code to the end of your code

int count=0;
for(int j=0;j<9;j++)
{
   if(userString.at(j) == 'x' )
       count++;
   if( count ==3)
   {
       cout<<"Three x's in a row";
       return 0;
   }
   if( (j+1)%3 == 0)
   {
       count=0;
   }
}

cout<<"No three x's in a row";