function tax = tax(agi)
%
%
%
status = 'M';
fedBracketSingle = [ 9700     .1;
                     39475    .12;
	             84201    .22;
		     160726   .24;
		     204101   .32;
		     510301   .35];
%		 
fedBracketMarried = [19400     .1;
                     78950    .12;
		     168400   .22
	             321450   .24;
		     408200   .32;
		     612350   .35];

if( agi < 0 )
  fprintf('Agi must be > 0.\n');
  return
end


		   
		   
if( status == 'M' )
  brackets = fedBracketMarried;
else
  brackets = fedBracketSingle;
end

tax = 0;
i = 1;
while( agi > brackets(i,1) )
  tax = tax + brackets(i,1)*brackets(i,2);
  if( i > length(brackets) )
    break;
  end
i = i+1;  
end
tax = tax + (brackets(i,1) - agi)*brackets(i,2);

fprintf('Effective Tax Rate = $%.2f%%\n\n',tax/agi*100)

return
