Post

Replies

Boosts

Views

Activity

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() }
Dec ’24
Reply to navigationstack
Darkpaw, Code is too big to send in 1 text. I have to send 2.import SwiftUI struct ContentView: View { @State var tipa: [Double] = [] @State var costa: [Double] = [] @State private var cost = "" @State private var paid = "" @State var tipp = "" @State var tipc = "" @State var tipaa = "" @State var totalcost = "" @State var totaltips = "" @State var totalcash = "" @State var tipcc = "" @State var numbc = "" @State var number = 0 @State var msg = "Enter cost and how much was paid. Enter numbers and one . decimal point only. Then press enter." @State var emsg = "" var body: some View { /* NavigationView { VStack { NavigationLink(destination: viewdetail()) { Text("click") .frame(width: 300, height: 150, alignment: .center) .background(Color.gray) .foregroundColor(.black) } } } */ ZStack { VStack { Text("Driver's Food Delivery") .font(.largeTitle) .fontWeight(.bold) Spacer() Text (msg) Spacer() Spacer() HStack { Text("Cost") .font(.largeTitle) .padding(10) Spacer() Text("Paid") .font(.largeTitle) .padding(10) Spacer() Text("Tip") .font(.title) Spacer() Text("Tip %") .font(.title) } HStack { TextField("Cost", text: $cost) .frame(width: 75, height: 25) .padding(20) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) .background(Color.brown) .cornerRadius(025) TextField("Paid", text: $paid) .frame(width: 75, height: 25) .padding(20) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) .background(Color.brown) .cornerRadius(025) Text(tipp) .frame(width: 75, height: 25) .background(Color.blue) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) Text(tipc) .frame(width: 75, height: 5) .padding(10) .background(Color.blue) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) } VStack { Button { enterp() } label: { Text("Enter") .font(.largeTitle) .foregroundColor(.green ) } Button { print("detail pressed") } label: { Text("Detail") .font(.largeTitle) .foregroundColor(.white ) } Button {print("delete pressed") } label: { Text("Delete") .font(.largeTitle) .foregroundColor(.red) } } VStack { Spacer() HStack { Spacer() Text("Avg Tip") .font(.title) Spacer() Text("Tip %") .font(.title) Spacer() Text("#") .font(.title) Spacer() } HStack { Spacer() Spacer() Spacer() Text(tipaa) .frame(width: 75, height: 25) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) Spacer() Spacer() Text(tipcc) .frame(width: 75, height: 5) .padding(10) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) Spacer() Text(numbc) .frame(width: 55, height: 5) .padding(10) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) Spacer() } } VStack { Spacer() HStack { Text("Total") .font(.title) Spacer() Text("Total") .font(.title) Spacer() Text("Total") .font(.title) } } VStack { HStack { Text("Cost") .font(.title) Spacer() Text("Tips") .font(.title) Spacer() Text("Cash") .font(.title) } } HStack {
Dec ’24
Reply to navigationstack
Import SwiftUI struct ContentView: View { @State var tipa: [Double] = [] @State var costa: [Double] = [] @State private var cost = "" @State private var paid = "" @State var tipp = "" @State var tipc = "" @State var tipaa = "" @State var totalcost = "" @State var totaltips = "" @State var totalcash = "" @State var tipcc = "" @State var numbc = "" @State var number = 0 @State var msg = "Enter cost and how much was paid. Enter numbers and one . decimal point only. Then press enter." @State var emsg = "" var body: some View {
Dec ’24
Reply to navigationstack
Thanks for your response. I need additional help. I have a screen and just want to go to another screen. I need step by step instructions. The video doesn't tell me where to put the code and he went too fast. Thanks again.
Dec ’24
Reply to navigationstack
Where does the code go? I'm using xcode 16 with swiftui. I started writing a program that keeps track of pizza deliveries. I got the first screen done but now I need to go to another screen where I will list all the deliveries and tips. On the first screen the user enters the cost of the delivery and what he got paid. The app then figures out the tip, tip%, avg tip, total tip %, how many deliveries, total cost and total tips. There's a button that says detail. This should take him to the second screen that will list all the deliveries and all the tips, high tip and low tip. Please let me know what other information you need. Thanks for your help.
Dec ’24
Reply to Checking for NIL
Thank you very much. I should've told you I'm a beginner. Where does that go? Right now all I have is this: @State private var cost = "" TextField("Cost", text: $cost) .frame(width: 75, height: 25) .padding(20) .fontWeight(.bold) .font(.system(size: 22)) .foregroundColor(.white) .background(Color.brown) .cornerRadius(025) Thanks again.
Nov ’24