Hello, I'm trying to create a character array that would find the absolute value of each value. Ex. Candadite: 111111 / Target: 444444. abs(1-4)(1-4)(1-4)(1-4)(1-4)(1-4) answer: 333333. I have the code running, but I get a consistant answer of 700, even when I move to a new Target set. If anyone could help I'd appreciate it greatly, thanks :)
Sorry if this is poorly discribed, I have attatched my project's word document if you need further details. Thanks again
#include <iostream>
#include <cmath>
#include <iomanip>
#include <Windows.h>
#include <fstream>
using namespace std;
void readit();
void calcit(char[10][6], char[3][6], char a, char b, char c, char d);
void writeit(int score1, int score2, int score3);
int main()
{
readit();
return 0;
}
void readit()
{
char candidate[10][6], target[3][6], a, b, c, d;
ifstream candidates("D:\\School\\C++ Programs\\Project 3\\candidates.txt");
ifstream targets("D:\\School\\C++ programs\\Project 3\\targets.txt");
//Declaring the format of table
for (char a = 0; a < 10; a++)
for (char b = 0; b < 6; b++)
{
//Declaring format of table "candidate"
candidates >> candidate[a][b];
}
for (char c = 0; c < 3; c++)
for (char d = 0; d < 6; d++)
{
//Declaring format of table "target"
targets >> target[c][d];
}
calcit(candidate, target, a, b, c, d);
}
void calcit(char candidate[10][6], char target[3][6], char a, char b, char c, char d)
{
int score1 = 0, score2 = 0, score3 = 0;
//Stating that all candidates and the first row of targets are to be compared
//and the absolute value is to be found
for (char a = 0; a < 10; a++)
for (char b = 0; b < 6; b++)
for (char c = 0; c < 1; c++)
for (char d = 0; d < 6; d++)
score1 = score1 + abs(b - d);
////Stating that all candidates and the second row of targets are to be compared
//and the absolute value is to be found
for (char a = 0; a < 10; a++)
for (char b = 0; b < 6; b++)
for (char c = 1; c < 2; c++)
for (char d = 0; d < 6; d++)
score2 = score2 + abs(b - d);
//Stating that all candidates and the third row of targets are to be compared
//and the absolute value is to be found
for (char a = 0; a < 10; a++)
for (char b = 0; b < 6; b++)
for (char c = 2; c < 3; c++)
for (char d =0; d < 6; d++)
score3 = score3 + abs(b - d);
writeit(score1, score2, score3);
}
void writeit(int score1, int score2, int score3)
{
//This table is not finished, trying to find the correct answer before continuing
cout << " Target Candidate Score";
cout << "---------------------------------------";
cout << score1 << endl;
cout << score2 << endl;
cout << score3 << endl;
}