#include iolib.h
#include printf1.h	/* PRINTF library */

#define questions 2	/* Number of questions in data file */
#define play 1

char answer,panswer;
int in,score,qcount;

/****************************************/
/* QUIZ written by Kevin Groves (C)1989 */
/* A multi-choice quiz game.            */
/* Put your questions in a file called  */
/* QUIZ.DAT, the layout for each quest  */
/* has to be as follows:                */
/*     text.......                      */
/*     ...........                      */
/*     ........... (any number of lines)*/
/*     !x                               */
/*     text......  etc.                 */
/*                                      */
/* where ! is the end of question marker*/
/* and x is the single upper case       */
/* answer to the question               */
/****************************************/
 
main()
{
while(play)
	{
	score=0;
	in=fopen("quiz.dat","r");
	qcount=questions;
	cls();
	while(qcount--)	/* Loop until all questions asked */
		{
		answer=readq();	/* Display question text and read answer */
		puts("\n\nPlease select your answer.\n");
		panswer=upper(getchar());	/* Input answer */
		if(answer==panswer)	/* Both same ? */
			{
			score++;
			bar("Correct  ");
			}
		else
			bar("Incorrect");
		}
	fclose(in);
	showscr();	/* Display score */
	if(newgame())	/* Another game ? */
		break;
	}
}


showscr()
{
bar("* * * * * * * * * * * * *");
printf("\nYour score is %d correct out of %d questions\n",score,questions);
bar(" * * * * * * * * * * * * ");
}

readq()
{
char c;
while((c=getc(in))!='!')
	putchar(c);

return upper(getc(in));
}

bar(str)
char str[80];
{
printf("\n\n%cp          %s          %cq\n\n",27,str,27);
}

newgame()
{
char yn;
printf("\n\nDo you want to play again (y/n) ?");
yn=upper(getchar());
if(yn=='Y')
	return 0;
else
	return 1;
}

cls()
{
printf("%cE%cH",27,27);
}
