mardi 22 août 2017

Else If Statement Swift

I'm trying to build an if/then basic app that will display the federal income tax for the values input in the .swift file in the label once the button is pressed. I'm planning on making the code more functional later, but wanted to test what I have. The only problem is, when I press the button, it shows 0.0, when it should be around 40...does anyone know what I'm doing wrong?

 @IBOutlet weak var Label: UILabel!
@IBAction func ButtonClicked(_ sender: Any) {
    var hourly:Float = 8.00
    var hours:Float = 61.75
    var exemptions:Float = 1.00
    var deductions:Float = 95.80
    var allowances:Float = (exemptions * deductions)
    var gross:Float = (hourly * hours)
    var taxable:Float = (gross - allowances)
    if taxable >= 17529 {
        var fedIncome = ((taxable * 0.396) + 5062.69)}
    else if taxable < 17529 && taxable >= 17458  {
        var fedIncome = ((taxable * 0.35) + 5037.84)}
    else if taxable < 17458 && taxable >= 8081  {
        var fedIncome = ((taxable * 0.33) + 1943.43)}
    else if taxable < 8081 && taxable >= 3925  {
        var fedIncome = ((taxable * 0.28) + 779.75)}
    else if taxable < 3925 && taxable >= 1677  {
        var fedIncome = ((taxable * 0.25) + 217.75)}
    else if taxable < 1677 && taxable >= 484  {
        var fedIncome = ((taxable * 0.15) + 38.80)}
    else if taxable < 484 && taxable >= 96  {
        var fedIncome = (taxable * 0.1)}
    else {
        var fedIncome:Float = 0.0}
     Label.text = ("\(fedIncome)")
}

Aucun commentaire:

Enregistrer un commentaire