{
cout << "You do not owe any income tax" << endl;
cout << "You will receive a refund of $ " << amount_tax_deducted << endl;
}
else if (taxable_income >= 12000 && taxable_income <= 20000.00)
{
tax_owed = taxable_income * rate_15percent;
remainder = 0.0;
refund = 0.0;
cout << "Amount of income: $ ";
cout << income_before_deductions << endl;
cout << "Number of qualifying dependents: ";
cout << number_of_dependents << endl;
cout << "Taxable income: $ ";
cout << taxable_income << endl;
cout << "Amount of income tax deducted: $ ";
cout << amount_tax_deducted << endl << endl << endl;
cout << "Tax on first $20,000 of taxable income $ " << tax_owed << endl;
cout << "Tax on next $30,000 of taxable income $ " << remainder << endl;
cout << "Tax on remaining taxable income $ " << remainder << endl;
cout << "Income tax surtax $ " << surtax_rate << endl;
cout << "You must pay a balance of $ " << tax_owed << endl;
cout << " You will receive a refund of $ " << refund << endl;
}
else if.....
Use your braces --
(a) it makes your code easier to read
(b) otherwise C/C++ will take only the first line as the action after the if.
I need to write an if-else statement for various different situations.
This is a small part of the code:
if (taxable_income < 12000)
cout << "You do not owe any income tax" << endl;
cout << "You will receive a refund of $ " << amount_tax_deducted << endl;
else if (taxable_income >= 12000 && taxable_income <= 20000.00)
tax_owed = taxable_income * rate_15percent;
remainder = 0.0;
refund = 0.0;
cout << "Amount of income: $ ";
cout << income_before_deductions << endl;
cout << "Number of qualifying dependents: ";
cout << number_of_dependents << endl;
cout << "Taxable income: $ ";
cout << taxable_income << endl;
cout << "Amount of income tax deducted: $ ";
cout << amount_tax_deducted << endl << endl << endl;
cout << "Tax on first $20,000 of taxable income $ " << tax_owed << endl;
cout << "Tax on next $30,000 of taxable income $ " << remainder << endl;
cout << "Tax on remaining taxable income $ " << remainder << endl;
cout << "Income tax surtax $ " << surtax_rate << endl;
cout << "You must pay a balance of $ " << tax_owed << endl;
cout << " You will receive a refund of $ " << refund << endl;
else if.....
The compiler is saying " illegal else without matching if" and I believe its because of the very long condition in the else-if statements. How can I resolve this problem if I need all of the stuff in the else to be true.