All pastes #382750 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-03-05 21:48 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int inGame ();

int main()
{
	printf("I have a number between 1 and 1000\nCan you guess my number?\nPlease type your first guess\nType e to end.\n\n");

	while (inGame () == 1);

	printf("Ending Game.\n");

	return 0;
}

int inGame ()
{
	int in, num;
	char end;

	printf("Guess:  ");

	num = 1+(rand ( ) % 1000);

	while (scanf("%d", &in) || scanf("%c", &end))
	{
		if (in == num && strcmp(&end, "y") == 1)
			return 1;
		else if (in == num && strcmp(&end, "n") == 1)
			return 0;
		else if (in == num)
			printf("Correct! Would you like to play again? (y or n)  ");

		if (strcmp(&end, "e") == 1)
			return 0;

		if(in < num)
			printf("Too low.  Try again:  ");
		else if(in > num)
			printf("Too high.  Try again:  ");
	}
	return 1;
}