subject

Modify the code to allow the user to enter any number of positive integers and calculate the average. In other words, the user could enter any number of positive integers. (Hint: You can prompt the user for how many they want to enter. Or; you could use a sentinel value to trigger when the user has completed entering values). Prepare a new test table with at least 3 distinct test cases listing input and expected output for the code you created. Support your experimentation with screen captures of executing the new code.

How can I make the code bellow allow any number of integers for the input?

// C code

// This program will calculate the sum of 10 positive integers.

// Developer: Faculty CMIS102

// Date: Jan 31,

#include

int main ()

{

/* variable definition: */

int count, value, sum;
double avg;

/* Initialize */

count = 0;

sum = 0;
avg = 0.0;

// Loop through to input values

while (count < 10)

{

printf("Enter a positive Integer\n");

scanf("%d", &value);
if (value >= 0) {
sum = sum + value;
count = count + 1;
}
else {
printf("Value must be positive\n");
}

}

// Calculate avg. Need to type cast since two integers will yield an integer

avg = (double) sum/count;

printf("average is %lf\n " , avg );

return 0;

}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 18:30
What type of weird relationship this is analogy show? dissolve: solidify: : noise: silence
Answers: 2
question
Computers and Technology, 21.06.2019 22:00
What is the most important aspect of marking media? a. data labelingb. content descriptionc. electronic labelingd. classification
Answers: 2
question
Computers and Technology, 22.06.2019 08:00
Apex q: what does a low employment rate indicate? a. not many people are earning high salaries b. not many people are going to college c. not many people are renting their homes d. not many people have jobs
Answers: 2
question
Computers and Technology, 23.06.2019 11:00
In the context of the box model, what is the difference between a margin and a padding? a. a padding lies outside a box border, while a margin lies inside it. b. a padding lies inside a box border, while a margin lies outside it. c. a padding can be adjusted independently, while a margin depends on the size of its box. d. a padding depends on the size of its box, while a margin can be adjusted independently.
Answers: 3
You know the right answer?
Modify the code to allow the user to enter any number of positive integers and calculate the average...
Questions
Questions on the website: 13722360