Tax Calculation Help

I have used this script to help me track how much each CD i buy costs including tax. It works as is, however if I buy 3 CD’s, I have to run script 3x to calculate tax for each CD. I want to calculate in one shot based on how many CD’s I select in the property section. Not sure how to accomplish. Any help would be helpful. Thanks

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

--use myLib : script "Script_Run_Log_Library"

--set myName to name of (info for (path to me))
--myLib's scriptRunLog(myName)

--property TotalCDs : {"1", "2", "3", "4", "5"}
--choose from list TotalCDs with prompt "Number of CD's bought:"
--set TotalCD to result as number

--What I'm trying to do here is loop thru based on number selected so I can calculate 
--tax for each CD instead of running this script multiple times. Not sure how to do this. 
--If I run this as is, it works but if I buy 3 CD's, I have run script 3 times to get total cost for each CD

display dialog "Enter total Cost:" default answer "" with title "Total Cost"
set totalSale to text returned of result

display dialog "Enter pre tax total:" default answer "" with title "Pre Tax"
set beforeTaxTotal to text returned of result

set salesTax to totalSale - beforeTaxTotal

display dialog "Sales tax: " & salesTax with title "Sales Tax"

set taxratio to salesTax / beforeTaxTotal

display dialog "The Tax Rate Is: " & taxratio & " % " with title "Tax Rate"

display dialog "Enter cost of the CD:" default answer "" with title " Cost of CD"
set CDCost to text returned of result

set TaxCD to CDCost * taxratio
set ThisCD to TaxCD + CDCost
display dialog "Total Tax is: " & TaxCD with title "Total Tax"
display dialog "Total Cost is " & ThisCD with title " Total Cost"

aspaceintime. I’m not sure I understand your request but try the following:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property TotalCDs : {"1", "2", "3", "4", "5"}

set theResult to choose from list TotalCDs with prompt "Number of CD's bought:"
if theResult is false then error number -128
set totalCD to item 1 of theResult as integer

repeat with i from 1 to totalCD
	
	display dialog "Enter total Cost for CD " & i & ":" default answer "" with title "Total Cost"
	set totalSale to text returned of result
	
	display dialog "Enter pre tax total:" default answer "" with title "Pre Tax"
	set beforeTaxTotal to text returned of result
	
	set salesTax to totalSale - beforeTaxTotal
	
	display dialog "Sales tax: " & salesTax with title "Sales Tax"
	
	set taxratio to salesTax / beforeTaxTotal
	
	display dialog "The Tax Rate Is: " & taxratio & " % " with title "Tax Rate"
	
	display dialog "Enter cost of the CD:" default answer "" with title " Cost of CD"
	set CDCost to text returned of result
	
	set TaxCD to CDCost * taxratio
	set ThisCD to TaxCD + CDCost
	display dialog "Total Tax is: " & TaxCD with title "Total Tax"
	display dialog "Total Cost is " & ThisCD with title " Total Cost"
	
end repeat

I can make it work in Excel, but that’s easy. I want to learn new skills to keep my brain active. I’m retired and have lots of time. It’s like a hobby.

I appreciate the help. I was not sure how to loop thru this scipt based on how many cd’s I buy. Before this tweak, If I bought 3, I ran 3x.