Program isn't printing correctly

后端 未结 5 1296
醉酒成梦
醉酒成梦 2021-01-28 04:52

I believe my program is still going through the if statements after it is declared invalid. It should print invalid filling status or invalid exemption status on the same line w

5条回答
  •  旧巷少年郎
    2021-01-28 05:28

    You might consider doing the following after the scanf:

    fillingStatus = toupper(fillingStatus);
    

    Then only test for the uppercase characters:

    fillingStatus == 'S'
    

    You need to fix your 'ifs' as suggested and print output like the following. It won't be quite right until you've fixed the 'ifs', though.

    if (taxExemptions > 12  || taxExemptions < 0) {
        printf("\n %d \t**** Invalid exemptions status ****", taxpayerId);
    } else {
        taxAmount = taxableIncome * taxRate;
        printf("\n %d \t %.2f \t\t %.2f \t %15.2f",taxpayerId,taxableIncome,taxRate,taxAmount);
    }
    

    The more I look at this code, the more I'm confused too. What should the tax rate be for someone with taxableIncome of 1 and fillingStatus == 'S'. I think it's going to be 0.31, since it's less than 20000. Probably not what you're going for. I think you're missing some 'else if' statments.

提交回复
热议问题