Illegal else without matching if?
Nov 29, 2015 at 5:21pm Nov 29, 2015 at 5:21pm UTC
I'm doing a project for school that calculates tax rates. I just started and I wanted to test it out. I never had this problem with "else if" statements before. I used "else if" before and it only gave me this error this time. I did a bit of research and I still don't understand what is going on. Thanks in advanced!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
int main()
{
int GrossIncome, NetIncome, TaxBracket2Remainder;
double AmountofTax;
const int TaxBracket1Total = 31000 * .2580;
const int DifferenceBetweenBracket1and2 = 45282 - 31000;
cout << "Hello!\nToday, this program shall calculate your net income using your gross income.\nAlso, if your gross income has cents in it, please round." << endl;
cout << "Please input your Gross income: " << endl;
cin >> GrossIncome;
cout << endl << endl;
if ((GrossIncome > 0) && (GrossIncome <= 31000));
{
AmountofTax = GrossIncome * .2580;
NetIncome = GrossIncome - AmountofTax;
cout << setprecision(2) << fixed << NetIncome << " is your net income if your gross income is " << GrossIncome << endl;
}
else if (GrossIncome > 31000)
{
TaxBracket2Remainder = GrossIncome - DifferenceBetweenBracket1and2;
AmountofTax = TaxBracket1Total + (TaxBracket2Remainder * .2775);
NetIncome = GrossIncome - AmountofTax;
cout << setprecision(2) << fixed << NetIncome << " is your net income if your gross income is " << GrossIncome << endl;
}
return 0;
}//end main
Nov 29, 2015 at 5:27pm Nov 29, 2015 at 5:27pm UTC
You have a semicolon on line 20 that should not be there
Nov 29, 2015 at 5:29pm Nov 29, 2015 at 5:29pm UTC
Silly me. How could I be so stupid!
Anyway thanks!
Topic archived. No new replies allowed.