• Forum
  • Lounge
  • Calculating values in two different file

 
Calculating values in two different files

So for I have to take values from one file named targets.txt which has 3 rows of values. each row has 6 values in it. I also have a file named candidates.txt. This has 10 rows of 6 values. From there I have to compare them. so basically the first value in the first row of candidates subtracted from the first in in the first row in targets, then the second in candidates from the second in targets, and so on. I want to do this in calcit. How exactly would I do that? If the values in the rows were summed and then subtracted, that would also work if thats easier, but i just don't know how to take values from files and use them together
using namespace std;

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


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


int main()
{
readit();

return 0;
}

void readit()
{

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

char targs[3][6], cands[10][6];

if(!intargs || !incands)
{
cout << "Your file streams are corrupted. Correct the problem and "
<< "try again." << endl;

Sleep(2000);
system("CLS");


}

// 'i' will index/identify targets, 'j' will index candidates,
// and 'k' will index characters within the targets and candidates

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

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

calcit(targs, cands);
}

void calcit(char targs[3][6], char cands[10][6])
{


writeit(targs, cands);
}

void writeit(char targs[3][6], char cands[10][6])
{
//tables and outputs.
cout << "answer" << endl;
}
Last edited on
You can edit your topic and move it to beginner or General C++ programming forum.

That way, you can get more helpful answers and replies.
Topic archived. No new replies allowed.