Question: /* DESCRIPTION: Reads sixteen integers from user input * and calculates the average of the positive values. * This code contains a single error. *

 /* DESCRIPTION: Reads sixteen integers from user input * and calculates

/* DESCRIPTION: Reads sixteen integers from user input

* and calculates the average of the positive values.

* This code contains a single error.

* Correct the error and submit the modified code.

*

****************************************************************

* IMPORTANT! IN THE PROVIDED COMMENT SPACE, WRITE ONE OR TWO *

* SENTENCES TO DESCRIBE THE ERROR AND YOUR SOLUTION *

****************************************************************

*/

#include

#include

#define MAX_COUNT 16

int main( void ) {

/* *****************************************************************

* COMMENT AREA: DESCRIBE THE ERROR IN THIS CODE AND YOUR SOLUTION *

* WRITE YOUR ANSWER HERE: *

*

*

*

*/

/* variable declarations */

int next_value;

int count_positive = 0;

int count_total = 0;

int sum_positive = 0;

double avg_positive;

/* read user input in a loop */

while (count_total

printf("Enter a positive or negative integer: ");

scanf("%d", &next_value);

/* test if next_value is a positive number */

if (next_value > 0) {

sum_positive += next_value;

count_positive++;

}

count_total++;

}

/* calculate and display the average of positive values if any were entered */

if (count_positive > 0) {

avg_positive = sum_positive / count_positive;

printf("Average of positive values: %.2lf ", avg_positive);

}

else {

printf("No positive values entered. ");

}

return 0;

}

In this question, you are given a completed program that contains a single error. The intended function of this program is to read sixteen values from the user and calculate the average of the positive values. Identify and correct the error, which will be found on a single line. In addition, briefly describe the error and its correction in the provided comment area in the code. You must write this comment to receive full marks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!