C scanf error

Write your question here.
In my code, scanf is keep passing leftover values to next scanf. I already used fflush, but it is not working. I attached both code and execution results.
Please help
Thanks
Also --> if(goStop != 'y'|| goStop != 'Y'){
didnt worked, so i had to change it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
int main(void){
	int loop1=1,asciiCheck,numOfCards;
	char goStop;
	 
	while(loop1==1){
		printf("Enter a number of cards(2-5):");
		fflush(stdin);
		scanf(" %d", &numOfCards);
		if(numOfCards ==2||numOfCards ==3||numOfCards ==4||numOfCards ==5){
			printf("Number of cards entered: %d\n", numOfCards);
			printf("Enter the faces of the cards (2-9,a,t,k,q,j) :\n");
		}else{
			printf("Error - Please enter a integer 2-5\n");
			printf("Type Y or y to try again:");
			fflush(stdin);
			scanf(" %c", &goStop);
			printf("You typed: %c\n", goStop);
			if(goStop == 'y'|| goStop == 'Y'){
			}else{
				printf("Bye\n");
				loop1=2;
			}
		}
		
	}
	return 0;
}



////result
Enter a number of cards(2-5):9
Error - Please enter a integer 2-5
Type Y or y to try again:y
You typed: y
Enter a number of cards(2-5):9oo
Error - Please enter a integer 2-5
Type Y or y to try again:You typed: o
Bye

Topic archived. No new replies allowed.