I am writing the following program:
The problem is that the program does not wait for user to press the enter in the first 24 group of numbers.It waits only after the second group.Probably in the first getchar() execution there is a new line character in the buffer.Code:
//Prints a table of squares using a for statement
#include <stdio.h>
#include <stdbool.h>
int main (int argc, const char * argv[]) {
// insert code here...
//declarations
int i, n;
printf("This program prints a table of squares.\n");
printf("Enter number of entries in table: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
printf("%10d%10d\n", i, i * i);
if (i % 24 == 0){
printf("Press Enter to continue...");
if (getchar() == '\n')
continue;
}
}
return 0;
}
Any ideas on how to handle this?
Thank you.