Change scanf("%c", &rep);
to scanf(" %c", &rep);
.
This is because a '\n' is left in stdin
the first time you input a number. When executing scanf("%c", &rep);
, that '\n' is immediately consumed by scanf()
and assigned to rep
. Since '\n' is equal to neither 'N' nor 'n', that loop continues.
With the leading space in the format string, all whitespace characters are discarded before reading starts. In your case, the invisible '\n' will be ignored, so that you can input a character.
Also, you should write char rep = 0;
instead, in case the original value of rep
happens to be 'n' or 'N'.