In this program , getchar
is apparently needed to continue the while(1) loop. If I remove getchar()
, the program terminates after printing the sum of the two numbers.
while (1) {
printf("Input two integers\n");
scanf("%d%d", &a, &b);
getchar();
c = a + b;
printf("(%d) + (%d) = (%d)\n", a, b, c);
printf("Do you wish to add more numbers (y/n)\n");
scanf("%c", &ch);
if (ch == 'y' || ch == 'Y')
continue;
else
break;
}