// C code // This program will calculate the sum of 10 positive integers. // Developer: Faculty CMIS102 // Date: Jan 31, XXXX #include <stdio.h> #include <stdbool.h> // needed for the Boolean variable debug. int main () { /* variable definition: */ int count, value, sum; int err; float avg; bool debug; /* Initialize */ count = 0; sum = 0; avg = 0.0; debug = false; // Loop through to input values while (count < 10) { printf("Enter a positive Integer\n"); err = scanf("%d", &value); if (debug) printf(" err = %d\n",err); if (debug) printf(" value is %d\n " , value ); //note the value of debug if (value >= 0) { sum = sum + value; count = count + 1; } else { printf("Value must be positive\n"); } } // 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 as float (as shown below) avg = (float) sum/count; printf("sum is %d\n", sum); printf("average is %f\n " , avg ); return 0; } Week 4 Classroom Lecture This week, the new pseudo commands are the Loops (or Repetitive) statements: A Repetitive (or Loop) statement is how you would execute the same block of code multiple times until some exit condition is met. There three types of Loops statements that we will learn. A Loop may be one of two types – pre test or post test. In a pre-test loop, the conditional test must be True before the code enters the loop. In a post-test loop, the code enters the loop first and then the conditional test is performed at the end of the loop to determine whether to exit or not. The three Loop statements are: Repeat goes thru loop at least once condition test is an exit conditional Until (condition is true) - post test – if condition is True, the code exits the loop While (condition is true) - pre test – if the condition is True, the code enters the loop condition test is an enter conditional End While For (initialize; test condition; increment) -pre test – if the condition is True, the code enters the loop condition test is an enter conditional builtin initialize counter builtin test condition – you can use constant, a variable, or an expression builtin increment – the increment is done at the end of the loop End For NOTE: The module readings has the pseudo-code for a For loop as For i = 1 step 1 to n We will NOT use this nomenclature. NOTE: The module readings also has Input statement without a prompt (Write) to the user as to what to enter. This bad practice as the user will be sitting there and not know that he is supposed to enter something. Your Input statements should always be preceded by a prompt (i.e. Write statement) to the user. Sentinel-controlled loop o a special value is used to exit the loop o this value is typically an invalid or il ...