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.
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;
}
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.