Kat H.

asked • 05/10/21

Add Negatives. The existing code is trying to call a function addNegatives that should take an array of ints and its size and return the sum of JUST the negative numbers from the array.

The existing code is trying to call a function addNegatives that should take an array of ints and its size and return the sum of JUST the negative numbers from the array. Your task is to write the missing function.


Example: given input of an array {-4 2 1 -3} and size 4 you should print -7


Code:


#include <iostream>


using namespace std;



//Do not modify anything on or above the line below this

//YOUR_CODE_BELOW


//YOUR_CODE



//YOUR_CODE_ABOVE

//Do not modify anything on or below the line above this



int main()

{

int NUM_VALUES; //cheating to make this flexible

cin >> NUM_VALUES;

int values[NUM_VALUES];

//Read in values

for(int i = 0; i < NUM_VALUES; i++) {

cin >> values[i];

}


int sum = addNegatives(values, NUM_VALUES);

cout << sum;

}

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.