Computers and Technology

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;

}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 00:00, lilyforeman5867
Match each vocabulary word to its definition.1. desktoppicture used to represent acomputer application2. domainnetwork protectionsoftware code that can be viewed,3. iconmodified, and redistributed for freethe background screen on acomputer monitor4. url5. blogan online journalthe part of an internet address that6. firewallrefers to a group of computers on anetworkonline database of web pages7. intranetnetwork for use by an individual8. open address of a web page or9. wikiresource
Answers: 2
image
Computers and Technology, 24.06.2019 01:00, arturocarmena10
The initial tableau of a linear programming problem is given. use the simplex method to solve it. x 1 x 2 x 3 s 1 s 2 z 1 2 4 1 0 0 8 3 4 1 0 1 0 10 minus3 minus12 1 0 0 1 0 the maximum is nothing when x 1equals nothing, x 2equals nothing, x 3equals nothing, s 1equals3, and s 2equals0. (be sure to simplify to lowest terms if necessary.)
Answers: 2
image
Computers and Technology, 24.06.2019 05:50, 11232003
What all vehicles has tesla inc. created over the years
Answers: 3
image
Computers and Technology, 24.06.2019 06:50, emmv565628
What are the things you are considering before uploading photos on social media?
Answers: 1
Do you know the correct answer?
Modify the code to allow the user to enter any number of positive integers and calculate the average...

Questions in other subjects:

Konu
Social Studies, 23.04.2021 01:00
Konu
Mathematics, 23.04.2021 01:00