diff --git a/Calculator.xcodeproj/project.pbxproj b/Calculator.xcodeproj/project.pbxproj index eedaf77..38f83b7 100644 --- a/Calculator.xcodeproj/project.pbxproj +++ b/Calculator.xcodeproj/project.pbxproj @@ -32,9 +32,6 @@ /* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ 7FB724422F8C2C38005B3C2D /* Exceptions for "Calculator" folder in "Calculator" target */ = { isa = PBXFileSystemSynchronizedBuildFileExceptionSet; - membershipExceptions = ( - TaxLogic.swift, - ); target = 7FB722212F8ACDE7005B3C2D /* Calculator */; }; /* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ @@ -43,9 +40,6 @@ 7FB724432F8C2C38005B3C2D /* Exceptions for "Calculator" folder in "Copy Bundle Resources" phase from "Calculator" target */ = { isa = PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet; buildPhase = 7FB722202F8ACDE7005B3C2D /* Resources */; - membershipExceptions = ( - TaxLogic.swift, - ); }; /* End PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */ diff --git a/Calculator.xcodeproj/project.xcworkspace/xcuserdata/harshitraj.xcuserdatad/UserInterfaceState.xcuserstate b/Calculator.xcodeproj/project.xcworkspace/xcuserdata/harshitraj.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..3a96447 Binary files /dev/null and b/Calculator.xcodeproj/project.xcworkspace/xcuserdata/harshitraj.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Calculator.xcodeproj/xcuserdata/harshitraj.xcuserdatad/xcschemes/xcschememanagement.plist b/Calculator.xcodeproj/xcuserdata/harshitraj.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..8d9f15f --- /dev/null +++ b/Calculator.xcodeproj/xcuserdata/harshitraj.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Calculator.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Calculator/ContentView.swift b/Calculator/ContentView.swift index f841a76..12091d2 100644 --- a/Calculator/ContentView.swift +++ b/Calculator/ContentView.swift @@ -6,11 +6,14 @@ // import SwiftUI +import Foundation struct ContentView: View { @State private var income = "" @State private var taxRate = "" - + @State private var taxAmount: Double = 0 + @State private var netIncome: Double = 0 + var body: some View { VStack(alignment: .leading, spacing: 0) { Text("Tax Calculator") @@ -48,7 +51,14 @@ struct ContentView: View { .shadow(color: .black.opacity(0.08), radius: 3, x: 0, y: 1) .padding(.bottom, 40) - Button("Calculate Tax") {} + Button("Calculate Tax") { + let incomeValue = Double(income) ?? 0 + let taxRateValue = Double(taxRate) ?? 0 + let result = calculateTax(income: incomeValue, taxRate: taxRateValue) + + taxAmount = result.taxAmount + netIncome = result.netIncome + } .frame(maxWidth: .infinity) .frame(height: 55) .background(Color(hex: "0A7CFF")) @@ -62,11 +72,11 @@ struct ContentView: View { .font(.system(size: 18, weight: .bold)) .foregroundColor(Color(hex: "1C1E21")) - Text("Tax Amount: ₹ 0.00") + Text("Tax Amount: ₹\(taxAmount, specifier: "%.2f")") .font(.system(size: 16)) .foregroundColor(Color(hex: "D93025")) - Text("Final Income: ₹ 0.00") + Text("Final Income: ₹\(netIncome, specifier: "%.2f")") .font(.system(size: 18, weight: .bold)) .foregroundColor(Color(hex: "1E8E3E")) } diff --git a/Calculator/TaxLogic.swift b/Calculator/TaxLogic.swift index d4c4bb8..edee081 100644 --- a/Calculator/TaxLogic.swift +++ b/Calculator/TaxLogic.swift @@ -13,6 +13,7 @@ /// - Returns: A tuple with the calculated `taxAmount` and the resulting `netIncome`. import Foundation func calculateTax(income: Double, taxRate: Double) -> (taxAmount: Double, netIncome: Double) { - - return (0, 0) -} \ No newline at end of file + let taxAmount = income * (taxRate / 100) + let netIncome = income - taxAmount + return (taxAmount, netIncome) +}