Question: MairoPizzaAppSt 1 9 issues @IBAction func addCart ( _ sender: UIButton ) { / / This function adds items to shopping cart var tempPrice =

MairoPizzaAppSt 19 issues
@IBAction func addCart(_ sender: UIButton){
// This function adds items to shopping cart
var tempPrice =0.0
var location =0// index in an array
var newitem = cart()// Temp Cart Variable
var num_of_items: Int =0// numberof item in array before adding it
var x : Int // counter variable
num_of_items = playerOrder.count // assigns num_of_items to number of items in myorder array
x = num_of_items // assign num_of_items to x
if (quantity !=0){// Check qty is greater than Zero
if (x maxorder)// check number of items in cart versus max cart capacity of 5
{
tempPrice = price * Double(quantity)// set for ext price
x +=1// add new line to the order
// Assign data to newitem cart variable
newitem.lineItem = x
newitem.order_qty = quantity
newitem.item_desc = menu
newitem.ext_Price = tempPrice
newitem.item_price = price
location = x-1// get next location in array
// insert newitem into playerOrder array at location x
playerOrder.insert(newitem, at: location)
// update ordertotal and bill variables
ordertotal = ordertotal + tempPrice
bill = ordertotal * tax }
else
{
// prints quanity to "Cart is full"
marioStart.text = "Cart is Full"
}
}
printorder()// upates viewcart label
bullitBill.text =" $"+ String(format:"%.2f",bill)// Updates billtext
}
@IBAction func removeItem(_ sender: UIButton){
// Remove one item from cart at line item x
var refund:Double! // Amount of money to removed from the bill and ordertotal
var removedLine: Int! // Line being deleted
var checkarray :Int! // amount of item in array
if (deleteLine.text !="")//check if user entered line item to delete
{
removedLine = Int(deleteLine.text!)
if (removedLine >0)// && removedLine playerOrder.count )// Check if removedline >0
{
refund = playerOrder[removedLine-1].ext_Price // get amount of refund from location
ordertotal = ordertotal - refund // updates ordertotal
bill = ordertotal * tax // updates bill
bullitBill.text = String(format:"%.2f",bill)//change billtext
playerOrder.remove(at: removedLine-1)// remove object from player orderder array
checkarray = playerOrder.count
if (checkarray !=0)
{
// array has items to print and updates it
printorder()
}
else if(checkarray ==0)
{
// array is empty reset the app
resetApp()
}
}
else // check if zero or less, Cause an erro{
deleteLine.text = "ERR"
}
}
}
func printorder()
{
// update Viewcart label
var newline =""
let arrayct = playerOrder.count
if (arrayct ==1)// Print 1st item only
{
newline = String(playerOrder[0].lineItem)+""+ String(playerOrder[0].order_qty)+" Each"+playerOrder[0].item_desc+" $"+ String(format:"%.2f",playerOrder[0].ext_Price)
marioText.append(newline)
}
else if(arrayct>1)// Print all items
{
let ni = arrayct-1
marioText =""
for index in 0...ni {
newline = String(playerOrder[index].lineItem)+""+ String(playerOrder[index].order_qty)+ "Each"+playerOrder[index].item_desc+" $"+ String(format:"%.2f",playerOrder[index].ext_Price)
newline.append ("
")
marioText.append(newline)
}
}
else // shows empty cart
{
marioText =""
}
// viewcart to ordertext
if marioText !="
{
cartView.text = marioText
}
else
{
cartView.text = "EMPTY CART"
}
}
@IBAction func payBill(_ sender: UIButton){
var change: Double =0.00
if (payMario.text !="")
{
let pay = Double(payMario.
Big blue box is a shopping cart. The line items are cart structures. example of line item (1.1 small soda $2.00)I got everything working execpt the empty cart button and print order needs to rest to orginal state. (picutre is orginal state) How do I remove line items from the cart structure items when I print order or empty cart? This is swift code cartView is the name of the box in my code. Top two items in second picture are from previous order in second pic.
MairoPizzaAppSt 1 9 issues @IBAction func addCart

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!