{ Improved Cash Register Program } Program CashRegister2 (input, output); uses crt; var Num_items : integer; {number of items the customer buys} Price, {price of one item} Bill, {total bill} Amt_Payed, {amount payed by the customer} Change : {amount of change they customer gets} real; {penny...} p, n, d, q, o, f, t, tw: {...through twenty} integer; const Tax = 0.0775; {sales tax rate} Procedure GetInfo (var Num_items: integer; var Price, Amt_Payed: real); begin ClrScr; Write('How many items were bought? '); Readln(Num_items); Write('How much did each item cost? $'); Readln(Price); Write('How much did the customer pay? $'); Readln(Amt_Payed); end; {GetInfo} Procedure CalcBill (Num_items: integer; Price, Tax: real; var Bill: real); begin Bill := (Num_items * Price) * (Tax + 1); Change := Amt_Payed - Bill; end; {CalcBill} Procedure ComputeCoins (MoneyVal: integer; var Number, Amt_left: integer); begin Number := Amt_left div MoneyVal; Amt_left := Amt_left mod MoneyVal; end; {ComputeCoins} Procedure CalcChange (var p, n, d, q, o, f, t, tw : integer; Change: real); var Amt_Left: integer; {Remaining change to compute} begin Amt_Left := Round(Change * 100); ComputeCoins (2000, tw, Amt_left); {Twenty} ComputeCoins (1000, t, Amt_left); {Ten} ComputeCoins (500, f, Amt_left); {Five} ComputeCoins (100, o, Amt_left); {One} ComputeCoins (25, q, Amt_left); {Quarter} ComputeCoins (10, d, Amt_left); {Dime} ComputeCoins (5, n, Amt_left); {Nickle} p := Amt_left; {Penny} end; {CalcChange} Procedure DispChange (var p, n, d, q, o, f, t, tw: integer); begin Writeln; Writeln('-----Change-----'); Writeln('Twenties: ', tw); Writeln('Tens: ', t); Writeln('Fives: ', f); Writeln('Ones: ', o); Writeln('Quarters: ', q); Writeln('Dimes: ', d); Writeln('Nickels ', n); Writeln('Pennies: ', p); Writeln('----------------'); end; {DispChange} begin GetInfo (Num_items, Price, Amt_Payed); CalcBill (Num_items, Price, Tax, Bill); Writeln; Writeln('Amount payed: $' , Amt_Payed:6:2); Writeln('Bill: $', Bill:6:2); Writeln('Change: $', Change:6:2); CalcChange(p, n, d, q, o, f, t, tw, Change); DispChange(p, n, d, q, o, f, t, tw); Writeln('Press any key to continue'); Readkey; end. {Program cashregister}