Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define BEGIN 0
- #define END 100
- //GOOD TO GIVE ANSWERS SUCH AS MM, LL, to figure EXACTLY how combination of scanf and getchar works
- int main(void)
- {
- char c;
- int middle;
- int begin,end = END;
- begin = BEGIN;
- printf("pick a secret number between %d and %d\n", begin,end);
- do
- {
- middle = (end + begin)/2;
- printf("i think you secret number is %d\n",middle);
- printf("input Y if i guessed right\n");
- printf("L if secret number is less, M if it's more\n");
- scanf("%c",&c);
- if(c=='L')
- {
- end = middle;
- }
- else if(c=='M')
- {
- begin = middle;
- }
- else if(c=='Y')
- break;
- else
- printf("your input is incorrect, try again\n");
- }while((c = getchar())!='Y'); //did it with this line, its totally ignored, when get to Y, which I totally
- //get. but why it's ignored all other times? have to rip it off everything, to figure it out
- //GOT it without ripping off! it's because scanf() gets symbol each time, and getchar() gets '\n'!
- // }while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement