Write a recursive function that reads a list of integers until a negative value is encountered and returns the sum of the nonnegatives read. The function may assume that the input is a valid list of integers containing at least one negative value.

What will be an ideal response?


```
int sumList ()
{
int num, ans;
cout << "Enter any number - negative to stop" << endl;
cin >> num; if (num < 0) ans = 0;
else

ans = num + sumList ();
return ans;
}
```

Computer Science & Information Technology

You might also like to view...

Data flow diagrams can be used for several different purposes.

What will be an ideal response?

Computer Science & Information Technology

Modifying an embedded chart in a Word document will ________

A) change the chart in both the Excel file and the Word file B) only change the chart in the Word file C) only change the chart in the Excel file D) change the chart in the Excel file only if it is open

Computer Science & Information Technology

Evaluate the following conditional expressions in a step-by-step manner as shown in the examples when x = 1 and y = 2.

Note: In the solutions below, indicate the current logical expression being evaluated according to the rules of precedence. ``` x=1 ORx=2 ORx=3 ``` Evaluates as True

Computer Science & Information Technology

Audit objectives for the database management system include all of the following except

A. verifying that the security group monitors and reports on fault tolerance violations B. confirming that backup procedures are adequate C. ensuring that authorized users access only those files they need to perform their duties D. verifying that unauthorized users cannot access data files

Computer Science & Information Technology