I'm not sure what you mean by 4) The boolean should match the guess peg/inner loop.
Here's what I did....
void Mastermind::getblackpegs()
{
for(int k=0; k<populationsize_; k++)
{
for(int i=0; i<4; i++)
{
if(population_[k][i]==answer_[i])
{
totalnumberofblackpegs_[k]++;
}
}
}
}
void Mastermind::gettotalnumberofpegs()
{
bool** guesscounted=(bool**)(malloc(sizeof(bool*)*populationsize_));
for(int i=0; i<populationsize_; ++i)
{
*(guesscounted+i)=(bool*)(malloc(sizeof(int)*4));
}
for(int i=0; i<populationsize_; i++)
{
for(int j=0; j<4; j++)
{
guesscounted[i][j]=false;
}
}
//through population
for(int k=0; k<populationsize_; k++)
{
//outer loop go through answer peg
for(int i=0; i<4; i++)
{
//through guess pegs
for(int j=0; j<4; j++)
{
if((population_[k][j]==answer_[i])&&!guesscounted[k][j])
{
totalnumberofpegs_[k]++;
guesscounted[i][j]=true;
}
}
}
}
}
void Mastermind::getwhitepegs()
{
for(int i=0; i<populationsize_; i++)
{
totalnumberofwhitepegs_[i]=totalnumberofpegs_[i]-totalnumberofblackpegs_[i];
}
}