1. Engineering
  2. Computer Science
  3. include ltstdiohgt int main int argc char argv int...

Question: include ltstdiohgt int main int argc char argv int...

Question details

#include <stdio.h>

int main (int argc, char** argv)

{

int i;

int count;

int total;

int val;

double average;

/* prompt the user for input */

printf ("Enter in a list of numbers followed by the terminal value of -999 ");

/* loop until the user enters -999 */

scanf ("%d", &val);

while (val != -999)

   {

total = total + val;

count++;

scanf("%d", &val);

   }

/* calculate the average of the values read in */

average = total / count;

/* display the results */

printf ("For the list of %d numbers with a total of %d ", count, total);

printf (" the average is: %15.5f ", average);

return 0;

}

Access the program lablb.c from the Lab Exercises page. This program is to read in a list of integers until the value of-999 is input. It then is to print out the number of value read, the total of these values and the average of these values. However, this program does contain some errors. 6. Fill in the table below with the expected values for the variables count, total and average if the program is run with input of 2 4 6 8 -999 Compile and run the program. Fill in the table below with the actual values produced by the program? Expected Value Actual Value Value of variable: count Value of variable: total Value of variable: average Does the program produce the expected output? If not, you may need to fix the error before moving to the next question. 7. Fill in the table below with the expected values for the variables count, total and average if the program is run with input of: 2 3 5 -999 Compile and run the program. Fill in the table below with the actual values produced by the program? Expected Value Actual Value Value of variable: count Value of variable: total Value of variable: average Does the program produce the expected output? If not, you may need to fix the error before moving to the next question.8 program is run with input of: 8. Fill in the table below with the expected values for the variables count, total and average if the -999 Compile and run the program. Fill in the table below with the actual values produced by the program? Expected Value Actual Value Value of variable: count Value of variable: total Value of variable: average Does the program produce the expected output? 9 What errors contained in the program were exposed in the above test cases? 10. Give a definition that would define when we can call a program error free

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution