Pegun
Golden Member
Hey guys, New problem, a different day. I'm trying to make a problem that detects a sequence of 3 or more in the array defined. It keeps not detecting the lower rows for some reason (2nd to last row doesnt detect the triple d's) Any help is greatly appreciated.
// updateBoard.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char BoardRow[8][8] =
{'c','c','c','d','a','a','a','c',
'a','c','c','c','d','d','d','b',
'a','a','c','c','c','b','b','b',
'a','c','a','c','c','d','c','a',
'b','c','c','d','d','c','a','b',
'a','c','c','d','c','d','d','d',
'd','c','c','d','d','a','a','a',
'a','c','c','c','c','d','a','b'
};
int start, end;
for(int r=0; r<8; r++)
{
for (int c=0; c<8; c++)
cout << BoardRow[r][c];
cout << endl;
}
for(int r=0;r<8;r++)
{
start = 0; end = 0; // set start and end to zero
for(int c=1; c<8; c++)
{
if(BoardRow[r][c] == BoardRow[r][c-1])
{end++;
}
else
{
end++;
//change chars from start to end to up if
//end - start >=3
if ((end-start) >= 3)
for(int cc = start; cc < end; cc++)
BoardRow[r][cc] += 'A' - 'a';
start = end;
}
cout << " (Start, End) = ( " << start << "," << end << " )" << endl;
}
for(int r=0; r<8; r++)
{
for(int c=0; c<8; c++)
cout << BoardRow[r][c];
cout << endl;
}
//{char ch; cin>>ch;} //This phrase, makes
//the program not do the columns
//until a character is input
}
return 0;
}
// updateBoard.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char BoardRow[8][8] =
{'c','c','c','d','a','a','a','c',
'a','c','c','c','d','d','d','b',
'a','a','c','c','c','b','b','b',
'a','c','a','c','c','d','c','a',
'b','c','c','d','d','c','a','b',
'a','c','c','d','c','d','d','d',
'd','c','c','d','d','a','a','a',
'a','c','c','c','c','d','a','b'
};
int start, end;
for(int r=0; r<8; r++)
{
for (int c=0; c<8; c++)
cout << BoardRow[r][c];
cout << endl;
}
for(int r=0;r<8;r++)
{
start = 0; end = 0; // set start and end to zero
for(int c=1; c<8; c++)
{
if(BoardRow[r][c] == BoardRow[r][c-1])
{end++;
}
else
{
end++;
//change chars from start to end to up if
//end - start >=3
if ((end-start) >= 3)
for(int cc = start; cc < end; cc++)
BoardRow[r][cc] += 'A' - 'a';
start = end;
}
cout << " (Start, End) = ( " << start << "," << end << " )" << endl;
}
for(int r=0; r<8; r++)
{
for(int c=0; c<8; c++)
cout << BoardRow[r][c];
cout << endl;
}
//{char ch; cin>>ch;} //This phrase, makes
//the program not do the columns
//until a character is input
}
return 0;
}