Question: Ruby So I'm assigned to make a cash register for my Ruby class. I'm still working on it so the code might look weird. But
Ruby
So I'm assigned to make a cash register for my Ruby class. I'm still working on it so the code might look weird. But I'm stuck on trying how to figure out how to keep track of how many item prices I'm entering while using option #1. I Get them all to add, but we are assigned to total the number of items when we total. How would I come to getting how many times I used the number and added a correct item price??
Code is below:
laborCharge = 0
discount = 0
totalPrice = 0
totalItemCount = 0
menuType = 0
menuID = -1
puts ("Welcome to the CIT Cash Register!")
puts
while menuID != 0
puts
puts
puts
puts ("Menu ID\t\tMenu Item")
puts ("-------\t\t---------")
puts ("1\t\t\tAdd Item Charge")
puts ("2\t\t\tAdd Labor Charge")
puts ("3\t\t\tApply Discount")
puts("4\t\t\tApply Gift Card")
puts("5\t\t\tTotal")
puts("9\t\t\tNew Transaction")
puts("0\t\t\tExit Application")
puts
print("Enter Menu ID: ")
menuID = gets().to_i()
case menuID
when 1
print("Enter item's charge amount: $")
itemCharge = gets().to_f()
itemCharge = itemCharge.round(2)
totalPrice += itemCharge
if itemCharge < 0.0
puts ("Item charge amount must be greater than 0. You entered " + itemCharge.to_s())
end
when 2
if laborCharge > 0
puts ("Labor charge has already been applied.")
else
print ("Enter labor charge amount: $")
ls = gets().to_f()
ls = ls.round(2)
if ls > 0.0
laborCharge = ls
else
puts ("Labor charge has to be greater than 0. You entered " + ls.to_s)
end
end
when 3
if discount > 0
puts ("Discount already applied.")
else
print("Enter discount percentage (5, 10 or 15): ")
da = gets().to_i()
if da == 5 or da == 10 or da == 15
discount = da
else
puts ("Discount percentage must be 5, 10, or 15. You entered " + da.to_s())
end
end
when 4
print("Enter gift card amount: $")
giftCard = gets().to_f()
giftCard = giftCard.round(2)
if giftCard < 0.0
puts ("Gift cars amount must be greater than 0. You entered " + giftCard.to_s())
end
when 5
puts ("Receipt")
puts ("Description\t\tQuantity\t\tAmount")
puts ("-----------\t\t--------\t\t------")
puts ("Items\t\t\t#{totalItemCount}\t\t\t#{totalPrice}")
puts ("Discount")
puts ("Tax")
puts ("Labor")
puts ("Grand Total")
puts
puts ("Gift Cards")
puts
puts
puts ("Please Pay Amount\t\t\t\t")
when 9
laborCharge = 0
discount = 0
totalPrice = 0
totalItemCount = 0
menuType = 0
when 0
puts ("Thanks for using the cash register.")
end
end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
