-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram
More file actions
59 lines (50 loc) · 1.73 KB
/
Copy pathprogram
File metadata and controls
59 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// ContentView.swift
// WeSplit
//
// Created by Achla Ajay on 20/09/24.
import SwiftUI
struct ContentView: View {
@State private var checkAmount=0.0
@State private var numberOfPeople=1
@State private var tipPercentage=20
let tipPercentages=[10,15,20,25,0]
var totalPerPerson:Double{
let PeopleCount=Double (numberOfPeople+2)
let tipSelection=Double(tipPercentage)
let tipValue=checkAmount / 100 * tipSelection
let grandTotal=checkAmount+tipValue
let amountperperson = grandTotal/PeopleCount
return amountperperson
}
var body: some View {
NavigationStack{
Form{
Section{
TextField("Amount",value: $checkAmount, format: .currency(code:Locale.current.currency?.identifier ?? "USD"))
.keyboardType(.decimalPad)
Picker("number of people", selection: $numberOfPeople){
ForEach(2..<100){
Text("\($0) people")
}
}
}
Section("How much do you want to tip?"){
Picker("Tip percentage", selection: $tipPercentage){
ForEach(tipPercentages, id:\.self){
Text($0,format: .percent)
}
}
.pickerStyle(.segmented)
}
Section{
Text(totalPerPerson, format: .currency(code:Locale.current.currency?.identifier ?? "USD"))
}
}
.navigationTitle("WeSplit")
}
}
}
#Preview {
ContentView()
}