Question: Modify the code to allow the user to enter any number of integers and calculate the sum and average. In other words, the user controls

Modify the code to allow the user to enter any number of integers and calculate the sum and average. In other words, the user controls the loop. (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).

Submit the C-code in text format in your "code" file.

// This program will calculate the sum of 10 integers. // Developer: Caleb Overbo // Date: April 09, 2020 #include  #include // needed for the Boolean variable debug. int main () {  //Header printf("Caleb Overbo CMIS 102/4065 April 09, 2020"); /* variable definition: */ int count, value, sum,ierr; float avg; bool debug; /* Initialize */ count = 0; sum = 0; avg = 0.0; debug = true; // Loop through to input values while (count < 10) { printf(" Enter an Integer number ");  scanf("%d", &value); if (debug) printf("valueis %d " , value );//note the value of debug  sum = sum + value; count = count + 1;  if (value >= 0) { sum = sum + value; count = count + 1; } else { printf(" >>>Value must be positive<<<"); } } // Calculate avg. // Since sum and count are both integers, this will give you an integer division // Hence, we need to either // Declare sum as a float or... //type cast sum asfloat (as shown below) avg = (float)sum/count; //Display results printf(" ---------------------- "); printf("sum is %d ", sum); printf("average is %0.3f " , avg ); return 0; } 

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 Programming Questions!