// guess.c -- an ineficient and faulty number-guesser
#include <stdio.h>

int main(void)
{
	int guess = 1;
	char response;

	printf("Pick an integer from 1 to 100. I will try to guess it.\n");
	printf("Respond with y if my guess is right and with n if it is "
	       "wrong\n");
	printf("Uh... is your number %d? ", guess);
	// get response, compare to 'y'
	while ((response = getchar()) != 'y')
	{
		if (response == 'n')
			printf("Well, then, it is %d? ", ++guess);
		else
			printf("Sorry, I understand only y or n.\n");
		while (getchar() != '\n')
			// skip rest of input line
			continue;
	}
	printf("I knew I could do it!\n");
	
	return 0;
}
