Modify the code to allow the user to enter an unspecified number of positive integers
Modify the code to allow the user to enter an unspecified number of positive integers and
calculate the average. In other words, the user could enter 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). You may need to conduct some research
on your own to solve this problem. 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.
// C code
// This program will calculate the sum of 10 positive integers.
// Developer: Alicia Bush, Student UMUC CMIS 102
// Date: Date: April 11, 2016
#include
int main ()
{
int counter = 0, num_values;
int num, sum = 0;
float average;
printf(“How many numbers to find the average for? “);
scanf(“%d”, &num_values);
//loop 10 times
while (counter printf(“Enter a number: “);
scanf(“%d”, &num);
sum = sum + num;
counter = counter + 1;
}
average = (float)sum/(float)num_values;
printf(“The average is %.2f\n”,average);
}
(stdin: 20 40 60 80)
It keeps giving me this average: 77.00 (THIS IS NOT RIGHT) Tha answer should be 50. I do not know what I am doing wrong.