Else If problem

At a certain point the else does not see the if and thinks that it requires an if. Does anyone know what I can do?

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  //Employee Payment Calculator

#include <iostream>
using namespace std;

int main()

{

	//Employee Options

	int empManager = 1;
	int empHourly = 2;
	int empCommission = 3;
	int empPiece = 4;
	int empSelection;
	int hours;
	int items;
	double rate;
	double sales;
	double itemValue;
	double salary;

	//Do-While Area

	do {

		//Employee Selection

		cout << "What type of employee are you?\n1- Manager\n2- Hourly Worker\n3- Comission Worker\n4- Pieceworker" << endl;
		cin >> empSelection;

		//Manager

		if (empSelection == empManager)
			cout << "Salary is $1500 a week!" << endl;

		//Hourly Worker

		else if (empSelection == empHourly)

			cout << "Enter hours worked." << endl;
			cin >> hours;
			cout << "Enter hourly rate of the worker. ($0.00)" << endl;
			cin >> rate;

			//Calculate Salary

			if (hours > 40)
				salary = (rate * 40) + ((rate * 1.5) * hours - 40);
			else
				salary = rate * hours;

			//Display Salary

			cout << "Salary is $" << salary << "!" << endl;

		//Commission Worker

		else if (empSelection == empCommission)
			
			cout << "Enter the amount of sales\nin money you have made ($0.00)." << endl;
			cin >> sales;

			salary = 250 + (sales * 0.057);

			cout << "Salary is $" << salary << "!" << endl;

			//Pieceworker

		else if (empSelection == empPiece)
			
			cout << "Enter the value you get\nper item. ($0.00)" << endl;
			cin >> itemValue;
			cout << "Enter the amount of items\nyou have worked on." << endl;
			cin >> items;

			//Calculate Salary

			salary = itemValue * items;

			cout << "Salary is $" << salary << "!" << endl;

			//Incorrect Employee Letter

		else
			
			cout << "Incorrect employee letter.\nPlease try again!" << endl;

	} while (empSelection > 0);
	
		return 0;

}
If there is more then one statement in a loop then you need to use curly brackets.

For example:

1
2
3
4
5
6
7
8
9
else if (empSelection == empHourly)

		{	
                        cout << "Enter hours worked." << endl;
			cin >> hours;
			cout << "Enter hourly rate of the worker. ($0.00)" << endl;
			cin >> rate;
                }
            
Thank you so much!
Topic archived. No new replies allowed.