My assignment was to create a tax calculator in whatever way possible initially with paying tax excluding tax brackets. How would I adjust this code to use Loops instead or how could I make it more efficient?
#include <stdio.h>
#include <stdlib.h>
int main()
{
double earnings; //user income
double tax; //sum of total tax
printf("=====================<><>TAX CALCULATOR (INC TAX BRACKETS)<><>=====================\n How much have you earned: \n");
scanf("%lf", &earnings);
double tax1 = earnings -12000; //seperating each tax bracket
double tax2 = earnings - 20000;
double tax3 = earnings - 40000;
double tax4;
double tax5;
if (earnings >= 12000 && earnings <=19999){
tax = (tax1*0.1);
printf("\nYou've made: %0.2f", earnings - tax);
printf("\nPaying: %0.2f in tax", tax);
}
else if(earnings >= 20000 && earnings <=39999){
//printf("\n============tax2: %0.2f============\n",tax2);
//printf("\n============Tax2: %0.2f============\n",tax2*0.15);
tax = (tax1*0.1 + tax2*0.15);
printf("\nYou've made: %0.2f", earnings - tax);
printf("\nPaying: %0.2f in tax", tax);
}
else if(earnings >= 40000){
tax = (tax1*0.1 + tax2*0.15 + tax3*0.2);
//printf("\n============tax3: %0.2f============\n",tax3);
//printf("\n============Tax3: %0.2f============\n",tax3*0.2);
printf("\nYou've made: %0.2f", earnings - tax);
printf("\nPaying: %0.2f in tax", tax);
}
else{
tax = 0;
printf("You made %0.2f", earnings);
printf("Paying: %0.2f", tax);
}
return 0;
}