Performing mathematical operation on data read from a file

I have posted the dataset and the coding, i need to subtract the set of 13 values from the dataset from the array c1[] and print the values. I am able to read the file print the values but unable to perform any operations on it. Whats is wrong with the code if anyone can help.



Dataset:

14.23,1.71,2.43,15.6,127,2.8,3.06,.28,2.29,5.64,1.04,3.92,1065
13.2,1.78,2.14,11.2,100,2.65,2.76,.26,1.28,4.38,1.05,3.4,1050
13.16,2.36,2.67,18.6,101,2.8,3.24,.3,2.81,5.68,1.03,3.17,1185
14.37,1.95,2.5,16.8,113,3.85,3.49,.24,2.18,7.8,.86,3.45,1480
13.24,2.59,2.87,21,118,2.8,2.69,.39,1.82,4.32,1.04,2.93,735
14.2,1.76,2.45,15.2,112,3.27,3.39,.34,1.97,6.75,1.05,2.85,1450
14.39,1.87,2.45,14.6,96,2.5,2.52,.3,1.98,5.25,1.02,3.58,1290
14.06,2.15,2.61,17.6,121,2.6,2.51,.31,1.25,5.05,1.06,3.58,1295
14.83,1.64,2.17,14,97,2.8,2.98,.29,1.98,5.2,1.08,2.85,1045
13.86,1.35,2.27,16,98,2.98,3.15,.22,1.85,7.22,1.01,3.55,1045
14.1,2.16,2.3,18,105,2.95,3.32,.22,2.38,5.75,1.25,3.17,1510
14.12,1.48,2.32,16.8,95,2.2,2.43,.26,1.57,5,1.17,2.82,1280
13.75,1.73,2.41,16,89,2.6,2.76,.29,1.81,5.6,1.15,2.9,1320

________________________________________________________________________________

#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <conio.h>

using namespace std;

int main()
{
double c1[13] = { 12.85, 1.6, 2.52, 17.8, 95, 2.48, 2.37, .26, 1.46, 3.93, 1.09, 3.63, 1015 };
int s = 0;
char word[100];
char filename[50];



ifstream fin;
fin.open("winedata.txt");
if (!fin.is_open())
{
exit(EXIT_FAILURE);
}
fin >> word;
while (fin.good())
{
for (int i = 0; i<13; i++)
{
s = s + word - c1[i];
cout << s << endl;
}
}
system("pause");
return 0;
}
I see several problems with your code.

First the extraction operator>> stops processing input when it encounters a white space character.

Second word is a character array, not a number, you can't do math using C-string. You need to iterate through the file and extract numbers, not strings.

Also please use code tags when posting code.

Topic archived. No new replies allowed.