Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Comment on the pH value of lattice solutions of salts.

Answered: 1 week ago