Post

Replies

Boosts

Views

Activity

Reply to array
Yes that works. But what if I don't know what's going to be in the array? It's for a pizza delivery program. The array holds the cost of the deliveries. In myfunc I want to print each element out to the screen. Thanks for your help.
2w
Reply to navigationstack
Darkpaw, Here is part 2. Text(totalcost) .frame(width: 95, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) Spacer() Text(totaltips) .frame(width: 95, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) Spacer() Text(totalcash) .frame(width: 95, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) } Spacer() } .frame( width: 400, height: 800) .background(Color.blue) } } func enterp() { var tippp = 0.0 var totalcsh = 0.0 var ttips = 0.0 var tcost = 0.0 var tipo = 0.00 tipo = (Double(paid)! - Double(cost)!) tipa.append (tipo) costa.append (Double(cost)!) number += 1 numbc = String(number) ttips = (tipa.reduce(0, +)) tcost = (costa.reduce(0,+)) tippp = (ttips / Double(number)) tipaa = tippp.formatted(.currency(code: "USD")) totaltips = ttips.formatted(.currency(code: "USD")) totalcost = tcost.formatted(.currency(code: "USD")) tipp = tipo.formatted(.currency(code: "USD")) tipc = String(tipo / Double(cost)! * 100) print(tipc) // let percentString = String(format: "%4.2f", tipc) + "%" tipcc = String(ttips / tcost * 100) totalcsh = (tcost + ttips) totalcash = totalcsh.formatted(.currency(code: "USD")) } } #Preview { ContentView() }
4w