I keep getting Bracket errors and I have no idea why.

Hey guys I created a program to calculate commission but I keep getting errors that i have bracket where they are not needed I need some help.

Heres the Code:


#include <iostream>
#include <iomanip>
using namespace std;

int getSalesAmt();
float calcCommission(float comission);
float calcPay(float commission);
void displayPay( int Amt, float commission, float basePay, float totalPay);


int main();
{
int Amt;
char answer = 'Y';
Amt = getSalesAm();

while (toupper(answer) == 'Y')
{
int display (int Amt, float commission, float basePay, float totalPay);
cout << "Dot it again (Y or N)";
cin >> answer;

if (toupper(answer)== 'Y')
{
Amt = getSalesAmt();
}

}
return 0;
}
int getSalesAmt();
{ int Amt;
cout << "Please enter the sales amount: ";
cin >> Amt;
return Amt;
}

float calcCommission(double commission, int Amt)
{ if (Amt >= 50000)
{
commission = .02;
}
if (Amt >= 25000 and Amt <= 50000)
{
commission = .015;
}
else
{
commission = 0;
}
return commission;
}

float calcPay(float commission)
{
float totalPay;
float basePay;
basePay = 2500 * commission;
totalPay = basePay + commission;
return totalPay;
}
void displayPay( int Amt, float commission,float basePay, float totalPay);
{
cout << "Monthly Sales: $" << fixed << setprecision(2) << showpoint << Amt << endl;
cout << " Commission: $" << fixed << setprecision (2) << showpoint << commission << endl;
cout << " Base Pay: $" << fixed << setprecision (2) << showpoint << basePay << endl;
cout << " Total Pay: $" << fixed << setprecision (2) << showpoint << totalPay << endl; << endl;
}
}

===============================================================================
These are the bracket errors:

main.cpp:12:1: error: expected unqualified-id
{
^
main.cpp:32:1: error: expected unqualified-id
{ int Amt;
^
main.cpp:63:2: error: expected unqualified-id
{
^
main.cpp:69:1: error: extraneous closing brace ('}')
}
^




Check your function definitions - in a few cases you have a ; that shouldn't be there, e.g.

int main(); // should be int main()


Also an extra endl and typo in function name.
1
2
3
cout << " Total Pay: $" << fixed << setprecision (2) << showpoint << totalPay << endl; << endl; // extra endl;

Amt = getSalesAm(); // typo on function name 


edit: and I think extra } at end.
Last edited on
Okay I adjusted the extra brace and the ; I am now getting these two errors that tell me that i need a ; after the Amt = getSalesAmt() and that i dont need a { before int Amt;

main.cpp:25:24: error: expected ';' after expression
Amt = getSalesAmt()
^
;
main.cpp:32:1: error: expected unqualified-id
{ int Amt;
^
2 errors generated
Without syntax errors. Didn't review it at all otherwise.

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
#include <iomanip>
#include <iostream>
using namespace std;

int getSalesAmt();
float calcCommission(float comission);
float calcPay(float commission);
void displayPay(int Amt, float commission, float basePay, float totalPay);

int main() {
  int Amt;
  char answer = 'Y';
  Amt = getSalesAmt();

  while (toupper(answer) == 'Y') {
    int display(int Amt, float commission, float basePay, float totalPay);
    cout << "Dot it again (Y or N)";
    cin >> answer;

    if (toupper(answer) == 'Y') {
      Amt = getSalesAmt();
    }
  }
  return 0;
}
int getSalesAmt() {
  int Amt;
  cout << "Please enter the sales amount: ";
  cin >> Amt;
  return Amt;
}

float calcCommission(double commission, int Amt) {
  if (Amt >= 50000) {
    commission = .02;
  }
  if (Amt >= 25000 and Amt <= 50000) {
    commission = .015;
  } else {
    commission = 0;
  }
  return commission;
}

float calcPay(float commission) {
  float totalPay;
  float basePay;
  basePay = 2500 * commission;
  totalPay = basePay + commission;
  return totalPay;
}

void displayPay(int Amt, float commission, float basePay, float totalPay)
{
  cout << "Monthly Sales: $" << fixed << setprecision(2) << showpoint << Amt
       << endl;
  cout << " Commission: $" << fixed << setprecision(2) << showpoint
       << commission << endl;
  cout << " Base Pay: $" << fixed << setprecision(2) << showpoint << basePay
       << endl;
  cout << " Total Pay: $" << fixed << setprecision(2) << showpoint << totalPay
       << endl;
}
Last edited on
This is definitely not the best solution. But it gets the job done.
Things to remember:
1) Use double instead of float.
2) When you declare a function you don't need to write variable names in:
1
2
void displayPay(int Amt, float commission, float basePay, float totalPay); // Ok.
void displayPay(int, float, float, float);                                 // Same as above. 

3) When you define a function don't put a semicolon at the end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void displayPay( int Amt, float commission,float basePay, float totalPay); // error.
{
        cout << "Monthly Sales: $" << fixed << setprecision(2) << showpoint << Amt << endl;
        cout << "Commission: $" << fixed << setprecision (2) << showpoint << commission << endl;
        cout << "Base Pay: $" << fixed << setprecision (2) << showpoint << basePay << endl;
        cout << "Total Pay: $" << fixed << setprecision (2) << showpoint << totalPay << endl;
}

void displayPay( int Amt, float commission,float basePay, float totalPay)  // Ok.
{
        cout << "Monthly Sales: $" << fixed << setprecision(2) << showpoint << Amt << endl;
        cout << "Commission: $" << fixed << setprecision (2) << showpoint << commission << endl;
        cout << "Base Pay: $" << fixed << setprecision (2) << showpoint << basePay << endl;
        cout << "Total Pay: $" << fixed << setprecision (2) << showpoint << totalPay << endl;
}


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
#include <iostream>
#include <iomanip>

using namespace std;

int getSalesAmt();
double calcCommission(int);
double calcBasePay(double);
double calcPay(double);
void displayPay(int, double, double, double);

int main()
{
        while (true)
	{
		int amt = getSalesAmt();
		cout << endl;
		double commission = calcCommission(amt);
		double base_pay = calcBasePay(commission);
		double pay = calcPay(commission);
		displayPay(amt, commission, base_pay, pay);
		cout << endl;

	repeat:
		cout << "Do it again (Y or N) ";
		char answer;
		cin >> answer;
		answer = toupper(answer);

		if (answer == 'Y')
		{
			system("CLS");
			continue;
		}
		else if (answer == 'N')
			return 0;
		else
		{
			system("CLS");
			goto repeat;
		}
	}
	return 0;
}

int getSalesAmt()
{
	cout << "Please enter the sales amount: ";
	int amt;
	cin >> amt;
	return amt;
}

double calcCommission(int amt)
{
	double commission = 0.0;

	if (amt >= 50000)
	{
		commission = .02;
	}
	else if (amt >= 25000 && amt <= 50000)
	{
		commission = .015;
	}
	else
	{
		commission = 0;
	}
	return commission;
}

double calcBasePay(double commission)
{
	double base = 2500 * commission;
	return base;
}

double calcPay(double commission)
{
	double totalPay;
	double base = 2500 * commission;
	totalPay = base + commission;
	return totalPay;
}

void displayPay(int amt, double commission, double basePay, double totalPay)
{
	cout << "Monthly Sales:\t\t$" << fixed << setprecision(2) << showpoint << amt << endl;
	cout << "Commission:\t\t$" << fixed << setprecision(2) << showpoint << commission << endl;
	cout << "Base Pay:\t\t$" << fixed << setprecision(2) << showpoint << basePay << endl;
	cout << "Total Pay:\t\t$" << fixed << setprecision(2) << showpoint << totalPay << endl;
}
Last edited on
Awesome made the corrections Appreciate the help ! Ran perfectly.
HandsomeJohn wrote:
2) When you declare a function you don't need to write variable names in:


But the program is easier to understand if you do, so I recommend not doing that :+)
Topic archived. No new replies allowed.