PROGRAM ATM2 (input, output);

	USES crt;

	CONST
		valid = 1234;

	VAR
		acctnum, transaction: integer;
		balance, amount: real;

	BEGIN

	acctnum:=0;
	transaction:=4;
	balance:=100.00;

	clrscr;
	Writeln('What is your account number');
	Writeln('Valid number is 1234');
     	 Readln(acctnum);
	WHILE (acctnum <> valid) DO 
		BEGIN
		     Writeln('Invalid Number. Please re-enter.');
		     Writeln('you number is 1234');
		     Readln(acctnum);
		END; {account<>valid loop}

	Writeln('If you don''t want to use the ATM please enter');
	Writeln('        4 = Quit');
	Writeln;
	Writeln('Otherwise enter the transaction number that you would like to make?');
	Writeln('        1 = Deposit');
	Writeln('        2 = Withdrawal');
	Writeln('        3 = Inquiry');
	Readln(transaction);

	WHILE (transaction <> 4) DO
		BEGIN

		      WHILE (transaction = 1) DO
			 BEGIN
				Writeln('How much would you like to deposit');
				Writeln('Please enter in amount in the following form');
				Writeln('        XXX.xx');
				Readln(amount);
				balance:= balance + amount;
				Writeln;
				Writeln('Your revised balance is ', balance:7:2);
				Writeln('transaction complete.');

		      		Writeln('What transaction would you like to make now?');
		    		Writeln('        1 = Deposit');
		     		Writeln('        2 = Withdrawal');
		      		Writeln('        3 = Inquiry');
		      		Writeln('        4 = Quit');
		     		Readln(transaction);
				clrscr;
			     END; {transaction = 1}

		         WHILE (transaction = 2) DO
			    BEGIN
				Writeln('How much would you like to withdraw');
				Writeln('Please enter in amount in the following form');
				Writeln('        XXX.xx');
				Readln(amount);
				WHILE (amount > balance) DO 
				      BEGIN
				      	Writeln('Insufficient Funds for that transaction');
				      	Writeln('How much would you like to withdraw');
			     	      	Writeln('Please enter in amount in the following form');
				      	Writeln('        XXX.xx');
			  	      	Readln(amount);
			 	     END;   {amount>balance}
			 
			 	     	balance:= balance - amount;
				     	Writeln;
			  	     	Writeln('Your revised balance is ', balance:7:2);
				     	Writeln('transaction complete.');

		      		Writeln('What transaction would you like to make now?');
		    			Writeln('        1 = Deposit');
		     			Writeln('        2 = Withdrawal');
		      			Writeln('        3 = Inquiry');
		      			Writeln('        4 = Quit');
		     			Readln(transaction);
					clrscr;				   
			        END; {transaction = 2}

		            WHILE (transaction = 3) DO
			       BEGIN
 					Writeln('Your current balance is ', balance:7:2);
					Writeln;
					Writeln('transaction complete.');

		      			Writeln('What transaction would you like to make now?');
		    			Writeln('        1 = Deposit');
		     			Writeln('        2 = Withdrawal');
		      			Writeln('        3 = Inquiry');
		      			Writeln('        4 = Quit');
		     			Readln(transaction);
					clrscr;
			       END; {transaction = 3}

		END;   {transaction <> 4   -   so NOW transaction=4 and then quit}

            		clrscr;
		Writeln('Goodbye');
		Readln;
	
	END.

	