Hi, i am the beginner for c programming, hope someone can help me.
Why the second scanf function cannot run when i put the code inside the loop?
But the second scanf function will become normal and can run if without the loop.
The c compiler i use is gcc compiler.
here is the code
Thanks for anyone can help me.
I use the variable chrResponse to control the loop, when i key in Y or y it will continue the program.Code:#include<stdio.h> #include<stdlib.h> void main() { char chrResponse='N'; int intA ; do { printf("Please enter a number here !!"); scanf("%d", &intA); printf("Do you want to continue ? (Y/N); fflush(stdin); scanf("%c", &chrResponse); }while(chrResponse=='Y'||chrResponse=='y'); return; }
I initialize the chrResponse to 'n'. The problem is i can key in the first data for variable intA, but after that the program directly print the message"Do you want to continue" and terminate it, it dind't allow me to enter a value for chrRespond either i want to continue the program or not.
I hope some one can help let me know why it happpen.
Thanks.