如果ELSE声明没有正确计算OBJ C.

时间:2014-11-26 00:51:26

标签: ios objective-c xcode if-statement

我正在制作支票计算器。但是,由于某种原因,计算无法准确导出到标签。我缩小了对IF ELSE声明的错误估计。我正在为netPay计算,当我将这个NSLog放在所使用的数字括号内时,打印输出对Xcode来说是完美的。

NSLog(@"Netpay is %f", netPay);

然而,在代码的下方,我的NSLog显示我的准确数字值增加,导致标签中显示不准确的数字。

由于税收参数的原因,我有多个If Ifle语句。请告诉我,我的IF ELSE声明是否需要我错过的内容,或者我做错了什么或者没有批准。为了测试,我计算了一天工作总收入2218美元。在线ADP计算器表示它应该计算净支付为1,860.87美元,但我的测试设备上的价格为1896.67美元。在Xcode上打印的NSlog说,在这个等式中,我也获得了1,860.87美元,然而NSLog进一步下调了If Else声明中的1896.67美元。

float bonusRate = [self fetchActualValue:self.bonusTextField.text];
float deductionsRate = [self fetchActualValue:self.deductionTextField.text];
float dailyRate = [self fetchActualValue:self.dailyRateTextField.text];
float daysWorked = [self fetchActualValue:self.daysWorkedTextField.text];
float grossPay = dailyRate * daysWorked + bonusRate;
double bonusTax = .75;
float bonusLeft = bonusRate * bonusTax;
double ssRate = .0620;
double medRate = .0145;
double taxRate = .79;
double M10 = .10;
double E704 = 704.0;
double E2217 = 2217.0;
double MEMW0 = .69;
double MEMW0D = 494.0;
float medgrossrate = (grossPay - bonusRate) * medRate;
float ssgrossrate = (grossPay - bonusRate) * ssRate;
float twoTaxes= medgrossrate + ssgrossrate;
float netPay = (grossPay - bonusRate + bonusLeft) - twoTaxes;
float excessTax = grossPay - E704;
float MW0Tax = excessTax * M10;
double E151 = 151.30;
double M15 = .15;
float excessTax01 = grossPay - E2217;
float MW0Tax1 = excessTax01 * M15;
float MW0FinalTax = MW0Tax1 + E151;

- (IBAction)calculateButtonPressed:(UIButton *)sender

{

    if([self.stateTextField.text  isEqual: @"ME"])
{
    if ([self.filingStatusLabel.text isEqual:@"Married"] & [self.allowancesLabel.text isEqual:@"0"])
    {

        if (grossPay >= E704 || grossPay < E2217)
    {
        if (grossPay >= 1610 || grossPay <= 1669)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - .25;}
        else if (grossPay >= 1670 || grossPay <= 1729)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 4.25;}
        else if (grossPay >= 1730 || grossPay <= 1789)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 8.0;}
        else if (grossPay >= 1790 || grossPay <= 1849)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 12.0;}
        else if (grossPay >= 1850 || grossPay <= 1909)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 16.0;}
        else if (grossPay >= 1910 || grossPay <= 1969)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 20.0;}
        else if (grossPay >= 1970 || grossPay <= 2029)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 24.0;}
        else if (grossPay >= 2030 || grossPay <= 2089)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 28.0;}
        else if (grossPay >= 2090 || grossPay <= 2149)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 31.0;}
        else if (grossPay >= 2150 || grossPay <= 2217)
        {netPay = (grossPay - bonusRate) - MW0Tax - twoTaxes - 37.0;}
    }
        else if (grossPay >= 2217 || grossPay <= 6854)

        {   if (grossPay >= 2218 || grossPay <= 2229)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 37.0;
            NSLog(@"Netpay is %f", netPay);}
            else if (grossPay >= 2230 || grossPay <= 2309)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 42.0;}
            else if (grossPay >= 2310 || grossPay <= 2389)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 47.0;}
            else if (grossPay >= 2390 || grossPay <= 2469)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 52.0;}
            else if (grossPay >= 2470 || grossPay <= 2549)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 57.0;}
            else if (grossPay >= 2550 || grossPay <= 2629)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 63.0;}
            else if (grossPay >= 2630 || grossPay <= 2709)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 68.0;}
            else if (grossPay >= 2710 || grossPay <= 2789)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 73.0;}
            else if (grossPay >= 2790 || grossPay <= 2869)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 78.0;}
            else if (grossPay >= 2870 || grossPay <= 2949)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 83.0;}
            else if (grossPay >= 2950 || grossPay <= 3029)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 89.0;}
            else if (grossPay >= 3030 || grossPay <= 3109)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 94.0;}
            else if (grossPay >= 3110 || grossPay <= 3189)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 99.0;}
            else if (grossPay >= 3190 || grossPay <= 3269)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 104.0;}
            else if (grossPay >= 3270 || grossPay <= 3369)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 111.0;}
            else if (grossPay >= 3370 || grossPay <= 3469)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 117.0;}
            else if (grossPay >= 3470 || grossPay <= 3569)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 124.0;}
            else if (grossPay >= 3570 || grossPay <= 3669)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 130.0;}
            else if (grossPay >= 3670 || grossPay <= 3769)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 137.0;}
            else if (grossPay >= 3770 || grossPay <= 3869)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 143.0;}
            else if (grossPay >= 3870 || grossPay <= 3969)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 150.0;}
            else if (grossPay >= 3970 || grossPay <= 4069)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 156.0;}
            else if (grossPay >= 4070 || grossPay <= 4169)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 163.0;}
            else if (grossPay >= 4170 || grossPay <= 4269)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 169.0;}
            else if (grossPay >= 4270 || grossPay <= 4369)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 177.0;}
            else if (grossPay >= 4370 || grossPay <= 4489)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 187.0;}
            else if (grossPay >= 4490 || grossPay <= 4609)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 196.0;}
            else if (grossPay >= 4610 || grossPay <= 4729)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 206.0;}
            else if (grossPay >= 4730 || grossPay <= 4849)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 215.0;}
            else if (grossPay >= 4850 || grossPay <= 4969)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 225.0;}
            else if (grossPay >= 4970 || grossPay <= 5089)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 234.0;}
            else if (grossPay >= 5090 || grossPay <= 5209)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 244.0;}
            else if (grossPay >= 5210 || grossPay <= 5329)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 253.0;}
            else if (grossPay >= 5330 || grossPay <= 5449)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 263.0;}
            else if (grossPay >= 5450 || grossPay <= 5569)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 272.0;}
            else if (grossPay >= 5570 || grossPay <= 5689)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 282.0;}
            else if (grossPay >= 5690 || grossPay <= 5809)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 291.0;}
            else if (grossPay >= 5810 || grossPay <= 5929)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 301.0;}
            else if (grossPay >= 5930 || grossPay <= 6049)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 311.0;}
            else if (grossPay >= 6050 || grossPay <= 6169)
            { netPay = (grossPay) - (MW0FinalTax + twoTaxes) - 320;}
            else if (grossPay >= 6170 || grossPay <= 6289)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 330.0;}
            else if (grossPay >= 6290 || grossPay <= 6409)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 339.0;}
            else if (grossPay >= 6410 || grossPay <= 6529)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 349.0;}
            else if (grossPay >= 6530 || grossPay <= 6649)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 358.0;}
            else if (grossPay >= 6650 || grossPay <= 6769)
            {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 368.0;}

            NSLog(@"Netpay 1 is %f", netPay);
    }

    }

    }

1 个答案:

答案 0 :(得分:1)

else if (grossPay >= 3030 || grossPay <= 3109)
    {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 94.0;}
else if (grossPay >= 3110 || grossPay <= 3189)
    {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 99.0;}

应该是

else if (grossPay <= 3109)
    {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 94.0;}
else if (grossPay <= 3189)
    {netPay = (grossPay - bonusRate) - MW0FinalTax - twoTaxes - 99.0;}