1
0

trouble.c 487 B

12345678910111213141516171819202122
  1. // trouble.c -- misuse of =
  2. // will cause infinite loop
  3. #include <stdio.h>
  4. int main(void)
  5. {
  6. long num;
  7. long sum = 0L;
  8. int status;
  9. printf("Please enter an integer to be summed ");
  10. printf("(q to quit): ");
  11. status = scanf("%ld", &num);
  12. while (status = 1)
  13. {
  14. sum = sum + num;
  15. printf("Please enter next integer (q to quit): ");
  16. status = scanf("%ld", &num);
  17. }
  18. printf("Those integers sum to %ld.\n", sum);
  19. return 0;
  20. }