Write A Program That Requests The Price And Weight Of An Item In Pounds And Ounces, And Then Determines The Price Per Ounce.
Write a program that requests the price and weight of an item in pounds and ounces, and then determines the price per ounce.
So, the Price Per Ounce formula is TOTAL PRICE / OUNCE = PRICE PER OUNCE. I have no idea why the screenshot says another value.
Regardless, heres a simple Lua code for it.
For these kinds of questions, please write the language it is asking.
print("Enter the price of an item:")
price = tonumber( io.read() )
if not price then
print("Invalid Price")
return
end
--
print("Enter weight of item in pounds and ounces separately.")
--
print("Enter pounds: ")
pounds = tonumber( io.read() )
if not pounds then
print("Invalid Pounds")
return
end
--
print("Enter ounce: ")
ounce = tonumber( io.read() )
if not ounce then
print("Invalid ounce:")
return
end
-- CALCULATE
price_per_ounce = price / ounce
-- RETURN
print("------------------")
print("Price per ounce: $" .. price_per_ounce)
Comments
Post a Comment