I have a program that is supposed to read in values from user into a vector. My function is then supposed to keep a running sum and start from element 1 and compare element 2 to the sum(this point it is just element 1). Move to the next element, add element 2 to the sum and see if element 3 is greater than the sum of elements 1 and 2. I am supposed to print only the elements that are greater than the sum. I'm having trouble getting it to print out any values. Could someone please let me know what I might be doing wrong? Thanks
int main()
{
vector <int> theData;
int i;
cout<< "Enter in the list of integers ending with a -1" << endl;
do
{
cin >> i;
if (i==-1)
{
break;
}
theData.push_back(i);
}while(i!=-1);
int index = 1;
int runningSum = unsortedData[i];
largeValue(unsortedData, index, runningSum);
system("PAUSE");
return 0;
}
void largeValue(vector<int> myVector, int index, int runningSum)
{
int size = myVector.size();
if (index == size)
{
return;
}
if (myVector[index] > runningSum)
{
cout << myVector[index] << " ";
runningSum += myVector[index];
index = index +1;
largeValue(myVector, index, runningSum);
}
else if (myVector[index] < runningSum)
{
runningSum += myVector[index];
index = index + 1;
largeValue(myVector, index, runningSum);
}
}