PROGRAM SuperTutor;

{Programmer:	Gregory A. Perkins
				CS 65
				Super AddTutor Program
DUE:			20 Sep 96}

{This program accepts two numbers from the tutored student, adds the two numbers, accepts
	what the student feels the answer is and tells the student if he/she is right or wrong.
	In addition, the program allows the student to do all this 5 times, and if the student
	fails to get the right answer on the first attempt of a problem, the program allows the
	student to try again before displaying the correct answer.  Finally, the program displays
	the number of problems attempted and gives the student a progress report.}

{Variables declaration section}
VAR FirstNum, SecondNum, Sum, Answer, Count: INTEGER;
VAR FirstCorrect, SecondCorrect, Wrong: INTEGER; {Variables for display of performance report}
CONST Loop = 5;{Constant used to control the number of loop executions}

BEGIN
{Initialize performance report variables to zero}
FirstCorrect := 0;
SecondCorrect := 0;
Wrong := 0;

{Introduction}
WRITELN('Hello!  Welcome to the Super Tutor!!!');
WRITELN;
WRITELN('I will help you with addition.');
WRITELN('I will ask you to enter a set of two numbers, then I');
WRITELN('will ask you to enter the result of adding the two numbers.');
WRITELN('Then, I will tell you whether your answer was correct or');
WRITELN('incorrect.  If the answer was incorrect, I will give you');
WRITELN('a second chance before I tell you the correct answer.');
WRITELN;
WRITELN('We will do five problems together.  Then I will tell you');
WRITELN('how you did overall.  Good Luck!!!');
WRITELN;
WRITELN('Hit the ENTER key when you are ready to continue...');
READLN;{Pause and wait for user to hit a key}

FOR Count := 1 TO Loop DO{Execute the program a total of 5 times}

	BEGIN
	
	WRITELN;{Blank line provided for formatting of subsequent loops}
	
	{Display the problem number, so student is aware of progress}
	WRITELN('Problem number: ', Count:1);
	
	{Prompt user for two numbers to be added and store their values}
	WRITELN('Enter the first number, then enter the second.');
	READLN(FirstNum, SecondNum);
	
	{Determine what the correct answer to the problem is}
	Sum := FirstNum + SecondNum;
	
	{Prompt user for the answer and store the value}
	WRITELN('Now, please add these two numbers and enter your answer.');
	READLN(Answer);
	
	{Test to see if the user got the correct answer}
	IF (Answer = Sum) THEN{Correct answer -- congratulatory message}
		BEGIN
		WRITELN('Congratulations!  You got the right answer!');
		FirstCorrect := FirstCorrect + 1;{Update performance variable for report}
		END;
		
	IF (Answer <> Sum) THEN{Incorrect answer}
		BEGIN
		
		{Inform user that he/she has made an error}
		WRITELN('Oops!  You made a mistake.  Can you find it?');
		
		{Give the user another opportunity to get the correct answer}
		WRITELN('Please try again!');
		
		{Prompt user for the answer again and store the value}
		WRITELN('Add the two numbers again, and enter your answer.');
		READLN(Answer);
		
		{Test to see if the user got the correct answer the second time}
		IF (Answer = Sum) THEN{Correct answer -- congratulatory message}
			BEGIN
			WRITELN('Congratulations!  You got the right answer!');
			SecondCorrect := SecondCorrect + 1;{Update performance variable for report}
			END;
			
		IF (Answer <> Sum) THEN{Incorrect answer again -- display the correct answer}
			BEGIN
			WRITELN('I''m sorry, but the correct answer is: ', Sum:5);
			Wrong := Wrong + 1;{Update performance variable for report}
			END;
			
		END;{Finish second chance loop}
		
	END;{Finish initial answer testing loop}

{Display of progress report}
WRITELN('Hit the ENTER key to see your performance report...');
READLN;{Wait for user to hit the ENTER key}

{Display the number of problems attempted}
WRITELN('You attempted ',Loop:1,' addition problems.');

{Display the number of problems answered correctly on the first try}
WRITELN('You got ',FirstCorrect:1,' right on the first try.');

{Display the number of problems answered correctly on the second try}
WRITELN('You got ',SecondCorrect:1,' right on the second try.');

{Display the number of problems answered incorrectly}
WRITELN('You answered ',Wrong:1,' problems incorrectly.');
 
END.