Tilbage til slide -- Tastaturgenvej: 'u'  forrige -- Tastaturgenvej: 'p'  næste -- Tastaturgenvej: 'n'          control/sentinel-class-ex-bad-explained.c - Eksempel på sentinel-controlled loop - med typisk fejl og forklaring.Lektion 4 - slide 10 : 14
Program 4

/* Sentinel controlled loop - SEVERAL PROBLEMS - now explained */

#include <stdio.h>
#define SENTINEL -1

int main(void) {
  int sum, number;

  /* Initialization */
  sum = 0;





  while (number != SENTINEL){          /* number is not initialized! */
    /* Get a number */
    printf("Enter number (-1 terminates): ");
    scanf("%d", &number);

    /* Add number to sum */            /* sentinel is added to sum  */
    sum += number;
  }

  /* Report the output */
  printf("The sum is %d\n", 
         sum);

  return 0;
}