Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

/* 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

5. How do instructional objectives help learning to occur?

Answered: 1 week ago

Question

4. Help trainees set challenging mastery or learning goals.

Answered: 1 week ago