dimanche 3 octobre 2021

C programming calculation within if statement under switch

i am trying to write a code that allows a user to input a filing status and the income to calculate the tax owed. if filing status input is outside of 1-4 , program will exit. i'm trying to use the switch and if else if, but looks like i am stuck with the code generating the tax owed portion. whenever i input the income, it will not generate the tax owed amount. example, for case 1: in switch (last line) for filing status i input 1(for single) and input 20000 for income. the result should show $3000 but it gives me that the taxes owed is $0.00 below is the code i have so far.

#include<stdio.h>

int main()
{

//declaration  status = filing status , income = income input, taxOwed = tax owed calculation.
int status;
double income, taxOwed;

//data/input
printf("************Menu****************\n");
printf("1) Single\n");
printf("2) Married Filing Jointly\n");
printf("3) Married Filing Separately\n");
printf("4) Head of Household\n");
printf("5) Exit\n");
printf("\n");
printf("********************************\n");
printf("\n");
printf("Enter status : ");
scanf("%d", &status);

//processing switch with Calculation within each case
switch(status)
{
    case 5:
        printf("\n", status);
        printf("Exit Program...\n");
        break;
    case 6: case 7: case 8: case 9:
        printf("You entered a wrong status. Program Exit . . .");
        break;
    default:
        printf("You entered a wrong status. Program Exit . . .");
        break;
    case 1:
        printf("Enter your taxable TI: $");
        scanf("%.2f\n", income);
        if (0 < income <= 24000)
        {
            taxOwed = (income * 0.15);
            printf("\n");
            printf("The taxes owed are: $%.2f", taxOwed);
            break;
        }
        else if (24000 < income <= 58000)
        {
            taxOwed = 3600 + (0.28 * (income - 24000));
            printf("The taxes owed are: $%.2f", taxOwed);
            break;
        }

}

return 0;
}

any review and help is much appreciated. thank you

Aucun commentaire:

Enregistrer un commentaire