ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 03 May 2017 My Price 8.00

This program will calculate the sum of 10 positive integers

Using the code below, answer this question:

What happens if you entered a value other than an integer (to the below loop statement)? For example a float or even a string.

 

 

// C code
// This program will calculate the sum of 10 positive integers.
#include <stdio.h>
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 Integern");
  scanf("%d", &value);
  if (value >= 0) {
     sum = sum + value;
     count = count + 1;
  }
  else {
     printf("Value must be positiven");
  }
}
// Calculate avg. Need to type cast since two integers will yield an integer
avg = (double) sum/count;
printf("average is %lfn " , avg );
return 0;
}

Answers

(11)
Status NEW Posted 03 May 2017 04:05 AM My Price 8.00

-----------

Not Rated(0)