I got a test project. I don't know how to send a link. Can you help me? Thanks
Post
Replies
Boosts
Views
Activity
Thank you. I'll try to create a test project. What are the few reasons it could be?
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.
I can't find anything on String(format:). When I run that it returns 0.
thank you
Thanks. What if I don't know what's in the array?
Thank you
Thank you very much.
I get 0%. Here's my code:
print(tipc)
let percentString = String(format: "%.0f%%", tipc)
print(percentString)
18.181818181818183
0%.
What did I do wrong?
Thank you.
Thanks for your help.
Claude31,
What's wrong with my code? Thanks
Darkpaw,
You got my code. What else do you need?
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()
}