Hey guys and gals! How can I get this c++ code to allow the user to continuously
ID: 640522 • Letter: H
Question
Hey guys and gals! How can I get this c++ code to allow the user to continuously enter incomes and get taxes back, but if they enter an income of 0, the program will terminate? I have to use if-then-else statements. Thanks!
{
float income;
float tax;
printf("Enter income: ");
scanf("%f",&income);
if (income <9076){
tax=(income*.1);
}
else if (income <36901){
tax=(income-9075) * .15 + 907.5;
}
else if (income <89351){
tax=(income-36900) * .25 + 5081.25;
}
else if (income <186351){
tax=(income-89350) * .28 + 18193.75;
}
else if(income <405100)
tax=(income-186350) * .33 + 45353.75;
printf("The tax is: %.2f ",tax);
return 0;
}
Explanation / Answer
while(true)
{
float income;
float tax;
printf("Enter income: ");
scanf("%f",&income);
if(income == 0){
break;
}
else if (income <9076){
tax=(income*.1);
}
else if (income <36901){
tax=(income-9075) * .15 + 907.5;
}
else if (income <89351){
tax=(income-36900) * .25 + 5081.25;
}
else if (income <186351){
tax=(income-89350) * .28 + 18193.75;
}
else if(income <405100){
tax=(income-186350) * .33 + 45353.75;
}
printf("The tax is: %.2f ",tax);
}
return 0;