Illegal else without matching if

Hi I'm new to c++ and I'm trying to write a program for class that is to figure out the different salaries between employees and I'm getting an error for illegal else without matching if in line 32 but I can't figure out whats wrong or where the missing brace is.

here is the code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
int main () {
string name;
char EmployeeType;
double HourlyRate;
double Hours;
double sum;
double gross;
double overtime;
double BaseSal;
double TotalGross;
int piece;
int sale;
double commission;
int returns;
double PiecePay;
double BaseGross;
;cout << "Enter the employee name: ";
getline (cin, name);
;cout << "Enter the salary type. "
;cout << "\n\tH\tHourly. ";
;cout << "\n\tP\tHourly plus piece credit. ";
;cout << "\n\tS\tHourly plus sales commission. ";
;cout << "\nEnter response here -----> ";
cin >> EmployeeType;
if(toupper(EmployeeType) == 'H' || toupper (EmployeeType) == 'P' || toupper (EmployeeType) == 'S')
{
else
{
if(toupper(EmployeeType) != 'H' || toupper (EmployeeType) != 'P' || toupper (EmployeeType) != 'S')
cout << "*****INVALID ENTRY***** ";
}

if(toupper (EmployeeType) == 'H')
{
;cout << "\n\nEnter the employee's pay rate: ";
cin >> HourlyRate;
;cout << "Enter hours worked: ";
cin >> Hours;
if(Hours <= 40)
gross = HourlyRate * Hours;
else {
if(Hours > 40)
Hours = Hours - 40;
BaseSal = HourlyRate * 40;
sum = HourlyRate / 2;
overtime = sum + HourlyRate;
gross = overtime * Hours;
TotalGross = gross + BaseSal;
;cout << "\n\n\nEmployee's name: " << name;
;cout << "\nTotal gross: " << TotalGross << endl;
}
}
{



if(toupper(EmployeeType) == 'P')
{
;cout << "\nEnter hours worked: ";
cin >> Hours;
;cout << "\nEnter pay rate: ";
cin >> HourlyRate;
;cout << "\nEnter piece count: ";
cin >> piece;
if(piece <= 1000)
PiecePay = piece * 0.01;
else {
if(piece > 1001 && piece <= 5000)
PiecePay = piece * 0.015;
else{
if(piece > 5000)
PiecePay = piece * 0.02;
}
{
if(Hours <= 40)
gross = HourlyRate * Hours;
else {
if(Hours > 40)
Hours = Hours - 40;
BaseSal = HourlyRate * 40;
sum = HourlyRate / 2;
overtime = sum + HourlyRate;
gross = overtime * Hours;
BaseGross = BaseSal + gross;
TotalGross = BaseGross + PiecePay;
;cout << "\nEmployee name: " << name;
;cout << "\nBase gross pay: " << BaseGross;
;cout << "\nPiece pay: " << PiecePay;
;cout << "\nTotal gross: " << TotalGross << endl;
}
}
}
}
}

if(toupper(EmployeeType) == 'S')
{
;cout << "\nEnter hours worked: ";
cin >> Hours;
;cout << "\nEnter pay rate: ";
cin >> HourlyRate;
;cout << "\nEnter sales: ";
cin >> sale;
;cout << "\nEnter returns: ";
cin >> returns;

if(sale <= 5000)
commission = sale * 0.15;
else {
if(sale > 5000 && sale <= 10000)
commission = sale * 0.02368;
else {
if(sale > 10000 && sale <= 25000)
commission = sale * 0.02455;
else {
if(sale > 25000)
commission = sale * 0.02521;
}
}
}
{
if(Hours <= 40)
gross = HourlyRate * Hours;
else {
if(Hours > 40)
Hours = Hours - 40;
BaseSal = HourlyRate * 40;
sum = HourlyRate / 2;
overtime = sum + HourlyRate;
gross = overtime * Hours;
BaseGross = BaseSal + gross;
TotalGross = BaseGross + commission;
;cout << "\nEmployee name: " << name;
;cout << "\nBase gross pay: " << BaseGross;
;cout << "\nCommission: " << commission;
;cout << "\nTotal gross: " << TotalGross << endl;
}
}
}
system("PAUSE");
return 0;
}
}



Any help would be appreciated.
1
2
3
4
5
6
7
if(toupper(EmployeeType) == 'H' || toupper (EmployeeType) == 'P' || toupper (EmployeeType) == 'S')
{
else
{
if(toupper(EmployeeType) != 'H' || toupper (EmployeeType) != 'P' || toupper (EmployeeType) != 'S')
cout << "*****INVALID ENTRY***** ";
}


The format for an if statement should be:
1
2
3
4
5
6
7
8
9
10
11
12
if(condition)
{
 code here
}
else if(condition)
{
 more code here
}
else
{
 other code here
}


Notice you have 2 opening braces here but only 1 closing brace
*EDIT* Ninjaed :D
Ok, a couple things.

One, I am unsure as to why you are adding a ; before your cout statements, they should be unneeded, though I could be mistaken.

Two, this looks incorrect, your if statement points to nothing, leading into an else. There is nothing happening for this if statement.

1
2
3
4
5
6
7
if(toupper(EmployeeType) == 'H' || toupper (EmployeeType) == 'P' || toupper (EmployeeType) == 'S')
{
else
{
if(toupper(EmployeeType) != 'H' || toupper (EmployeeType) != 'P' || toupper (EmployeeType) != 'S')
cout << "*****INVALID ENTRY***** ";
}


Try this instead:

1
2
3
4
5
6
7
8
if(toupper(EmployeeType) == 'H' || toupper (EmployeeType) == 'P' || toupper (EmployeeType) == 'S')
{
//whatever you wanted to have happen
}//end if
else if (toupper(EmployeeType) != 'H' || toupper (EmployeeType) != 'P' || toupper (EmployeeType) != 'S') //make this an else if statement 
{
cout << "*****INVALID ENTRY***** ";
}


This should fix your issues. Also, you are missing a bracket in your code, thus giving you the error, re read over it, you can see some issues. Also, NEVER use the system("PAUSE");, it is a horrible habit, and you should never use it for programming projects that you plan on turning in for school or work. I think we have a sticky on it.
Last edited on
Thanks guys for the help. I understand what I was missing. Everything works fine now.
Topic archived. No new replies allowed.