Part 1.
import SwiftUI
struct ContentView: View {
@State var tipa: [Double] = []
@State var costa: [Double] = []
@State private var cost = ""
@State private var costt = Double?(0)
@State private var paidt = Double?(0)
@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 deletep = 0
@State var number = 0
@State var msg = "Enter cost and how much was paid. Enter numbers"
@State var msg2 = " and one . decimal point only. Then press enter."
@State var emsg = ""
var body: some View {
NavigationStack {
VStack
{
Text(" " + Date().formatted(date: .numeric, time: .omitted))
.foregroundColor(.black)
.fontWeight(.bold)
Text("Driver's Food Delivery")
.font(.largeTitle)
.fontWeight(.bold)
Image("Screenshot 2024")
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(.blue)
.background(Color.brown)
.cornerRadius(025)
TextField("Paid", text: $paid)
.frame(width: 75, height: 25)
.padding(20)
.fontWeight(.bold)
.font(.system(size: 22))
.foregroundColor(.blue)
.background(Color.brown)
.cornerRadius(025)
Text(tipp)
.frame(width: 95, height: 25)
.background(Color.white)
.fontWeight(.bold)
.font(.system(size: 22))
.foregroundColor(.blue)
Text(tipc)
.frame(width: 75, height: 5)
.padding(10)
.background(Color.white)
.fontWeight(.bold)
.font(.system(size: 22))
.foregroundColor(.blue)
}
VStack
{
Text (emsg)
.foregroundColor(.red)
Text (msg)
.foregroundColor(.blue)
HStack {
Text (msg2)
.foregroundColor(.blue)
Spacer()
}
Button { enterp()
}
label: { Text("Enter")
.font(.largeTitle)
.foregroundColor(.green )
}
NavigationLink(destination: viewdetail()) {
Text("Detail")
.frame(width: 100, height: 50, alignment: .center)
.background(Color.white)
.foregroundColor(.blue)
.font(.largeTitle)
}
Button {
delete(costa:&costa,tipa:&tipa, number: &number)
}
label: { Text("Delete")
.font(.largeTitle)
.foregroundColor(.red) }
}
VStack {
Spacer()
HStack
{
Spacer()
Text("Avg Tip")
.font(.title)
Spacer()
Spacer()
Text(" Tip %")
.font(.title)
Spacer()
Text(" #")
.font(.title)
Spacer()
}
HStack {
Spacer()
Spacer()
Spacer()
Text(tipaa)
.frame(width: 145, height: 25)
.fontWeight(.bold)
.font(.system(size: 22))
.foregroundColor(.blue)
Spacer()
Spacer()
Text(tipcc)
.frame(width: 120, height: 5)
.padding(10)
.fontWeight(.bold)
.font(.system(size: 22))
.foregroundColor(.blue)
Spacer()
Text(numbc)
.frame(width: 55, height: 5)
.padding(10)
.fontWeight(.bold)
.font(.system(size: 22))
.foregroundColor(.blue)
Spacer()
}
}