------------------ -- Sales Tax -- October 18, 2002 -- Malia Kilpinen -- 16.35 Problem Set 1a Example Solution -- -- Input: Lower boundary for price range, Upper Boundary for Price range, -- Increments in Table, Tax Rate As A Decimal Number in The range From 0 To 100% -- Output: prints tax table -- Note: This program does not use exception handling, as it was not introduced -- until after this problem set is due. ------------------- with Ada.Text_Io; with Ada.Float_Text_Io; use Ada.Text_Io; use Ada.Float_Text_Io; procedure Sales_Tax is -- declare variables Lower_Bound, Upper_Bound : Float; Increment, Tax_Rate, Temp_Bound, Cost, Tax : Float; begin -- set initial values Lower_Bound:= 0.0; Upper_Bound:= 0.0; Increment:= 0.0; Tax_Rate:= -1.0; Temp_Bound:= 0.0; Cost:= 0.0; Tax:= 0.0; -- Get inputs from user -- 1) get Lower_Bound -- Lower_Bound must be positive while Lower_Bound <= 0.0 loop Ada.Text_Io.Put (Item => "Enter lower bound for tax table (greater than zero): "); Ada.Float_Text_Io.Get (Item => Lower_Bound); end loop; -- 2) get Upper_Bound -- Lower_Bound must be less than Upper_Bound while Upper_Bound <= Lower_Bound loop Ada.Text_Io.Put (Item => "Enter upper bound for tax table (greater than lower bound): "); Ada.Float_Text_Io.Get (Item => Upper_Bound); end loop; -- 3) get Increment -- Increment taken to be positive. (No specification given in the problem.) while (Increment <= 0.0) loop Ada.Text_Io.Put (Item => "Enter the increment value (positive): "); Ada.Float_Text_Io.Get (Item => Increment); end loop; -- 4) get Tax_Rate -- Tax rate should be between 0 and 100, inclusive while (Tax_Rate < 0.0) or (Tax_Rate > 100.0) loop Ada.Text_Io.Put (Item => "Enter tax rate as percent (0-100%): "); Ada.Float_Text_Io.Get (Item => Tax_Rate); end loop; --------------------------- -- Start printing the table --------------------------- Ada.Text_Io.New_Line; Ada.Text_Io.Put("**********************Tax Table********************"); Ada.Text_Io.New_Line; Ada.Text_Io.Put(" Price without tax Tax Price with tax"); Ada.Text_Io.New_Line; -- Temp_Bound is just a variable used in the loop Temp_Bound := Lower_Bound; -- print each line in the loop while (Temp_Bound <= Upper_Bound) loop -- Calculations -- 1) calculate tax value Tax:=Tax_Rate*Temp_Bound/100.0; -- 2) calculate total cost Cost:=Temp_Bound + Temp_Bound*(Tax_Rate/100.0); -- Print Table Ada.Float_Text_Io.Put (Temp_Bound, 5, 2, 0); Ada.Float_Text_Io.Put (Tax, 17, 2, 0); Ada.Float_Text_Io.Put (Cost, 11, 2, 0); Ada.Text_Io.New_Line; Temp_Bound := Temp_Bound + Increment; end loop; -- end of printing-table loop end Sales_Tax; -- end of procedure!