I am trying to open files with list of int numbers. I just want to output the total number of numbers in the file, and add together all the numbers from the file.
This is the part that I am having problems with:
void workFunc(ifstream& myInput, string fileName, int& count, int& sum)
{
//int count = 0;
//int sum = 0;
int num;
myInput >> num;
while (myInput.good())
{
myInput >> num;
count++;
sum += num;
}
}
It is giving me the right count, but not adding the numbers together properly every time.