Indicating position in a 2D Array

I'm working on a project with targets and candidates. I have to indicate the closest candidate match to each of the three targets. Each candidate is given a score in a list of 10 and I need to indicate the position in that list.

using namespace std;

#include <iostream>
#include <iomanip>
#include <fstream>
#include <math.h>

void readit();
void calcit(char [3][6], char [10][6]);
void writeit(char [3][6], char [10][6], int [3][10], int [3]);

int main()
{
readit();

return 0;
}

void readit()
{
char targets[3][6];
char candidates[10][6];

ifstream intargs("C:\\EGR111\\targets.txt");
ifstream incands("C:\\EGR111\\candidates.txt");

for(int i = 0; i < 3; i++)
for(int j = 0; j < 6; j++)
intargs >> targets[i][j];

for(int i = 0; i < 10; i++)
for(int j = 0; j < 6; j++)
incands >> candidates[i][j];

calcit(targets, candidates);
}

void calcit(char targets[3][6], char candidates[10][6])
{
int scores[3][10] = {0};
int bestresult[3] = {0};

for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 10; j++)
{
for(int k = 0; k < 6; k++)
{
scores[i][j] += abs(targets[i][k] - candidates[j][k]);
}

if(j==0)
{
bestresult[i] = scores[i][j];
}

if(bestresult[i] > scores[i][j])
{
bestresult[i] = scores[i][j];
}
}
}

writeit(targets, candidates, scores, bestresult);
}

void writeit(char targets[3][6], char candidates[10][6], int scores[3][10],
int bestresult[3])
{
for(int i = 0; i < 3; i++)
{
cout << " Target " << i+1 << " Candidates Scores" << endl;
cout << "======================================" << endl;

for(int j = 0; j < 10; j++)
{
cout << setw(3) << ' ';

for(int k = 0; k < 6; k++)
{
cout << targets[i][k];
}

cout << setw(7) << ' ';

for(int k = 0; k < 6; k++)
{
cout << candidates[j][k];
}

cout << setw(10) << ' ';

cout << scores[i][j] << endl;
}

cout << endl;
int postn = bestresult[i]; // THIS IS WHERE I AM HAVING TROUBLE
cout << "The closest match is in position " << postn << "." << endl
<< endl << endl;
// IT READS THE SCORE VALUE NOT POSITION IN THE SCORE COLUMN
}
}
Topic archived. No new replies allowed.