### 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.
 ``123`` ``````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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263`` ``````#include #include 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:
 ``12`` ``````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.
 ``123456789101112131415`` ``````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; }``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293`` ``````#include #include 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.