sales commission program

I need some guidance on what to do next. I wrote the program as much as I could.

If you see a better way to fix my code, please let me know.

I want to finish my program, but I don't know what to do. Below are the instructions given to me, and how the Output must be displayed.

Include these 3 functions:
getSalesAmt
-This function prompts the user to enter a monthly sales amount.
-The amount is read and assigned to a variable.
-The value is then returned to main()

calcCommission
-This function calculates the commission based on the sales amount.
-If a salesperson sells more than $50,000. per month, the commission is 2% of the sales amount.
-If the sales are between $25,000 and $50,000., then the commission is 1.5% of the sales amount.
-However, if the sales are less than $25,000., there is no commission.
-The value is returned to main().

calcPay
-This function calculates the total monthly pay for a salesperson.
-A salesperson gets a monthly salary of $2,500. plus a commission, if the person earned a commission.
-The value is returned to main().

displayPay
-This function displays the total monthly pay for a salesperson.
-Format the output to two decimal places, and with the amounts aligned as shown.

/* ===== Output ========================================================
Enter a monthly sales amount: $

Monthly Sales: $

Commission: $

Base Pay: $

Total Pay: $

Do it again (Y or N)?

*/

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

int getSalesAmt();
void displayPay(int salesAmt);
float calcCommission(float commission);

int main()
{
	int salesAmt;

	char answer = 'Y';
	salesAmt = getSalesAmt();
	
	while (toupper(answer) == 'Y')
	{
		displayPay(salesAmt);

		cout << "Do it again (Y or N)?  ";
		cin >> answer;

		if (toupper(answer) == 'Y')
		{
			getSalesAmt();//doesn't display newly entered monthly sales.
		}
	}
	return 0;
}
int getSalesAmt()
{
	int salesAmt;

	cout << "Enter a monthly sales amount: ";
	cin >> salesAmt;

	return salesAmt;
}
float calcCommission(float commission, int salesAmt)
{
	float commission;

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

	return commission;
}
/*
float calcPay()
{

}
*/
void displayPay(int salesAmt)
{
	cout << "\nMonthly Sales:   $" << salesAmt << endl;
	cout << "\nCommission:      $" << fixed << setprecision(1) << showpoint << endl;
	cout << "\nBase Pay:        $" << fixed << setprecision(1) << showpoint << endl;
	cout << "\nTotal Pay:       $" << fixed << setprecision(1) << showpoint << endl << endl;
}
Last edited on
I think calcPay() should take the commission as a parameter and return the total pay:
float calcPay(float commission);

displayPay should take the sales amount, commission, base pay and total pay:
void displayPay(int salesAmt, float commission, float basePay, float totalPay);

I think you'll that with these parameters the functions are easy to write.
Been working on it, and this is what I have so far. I get a failed build response, so I can't tell if I'm making progress.
Any help would be appreciated, because I'm at a loss what to do to finish this by tomorrow. Thanks

Build errors I get are as follows.
Line 20 error C2660: 'displayPay' : function does not take 1 arguments
Line 43 error C2082: redefinition of formal parameter 'commission'
Line 47 warning C4305: '=' : truncation from 'double' to 'float'
Line 49 warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence
Line 51 warning C4305: '=' : truncation from 'double' to 'float'


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

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

int main()
{
	int salesAmt;

	char answer = 'Y';
	salesAmt = getSalesAmt();

	while (toupper(answer) == 'Y')
	{
		displayPay(salesAmt);

		cout << "Do it again (Y or N)?  ";
		cin >> answer;

		if (toupper(answer) == 'Y')
		{
			getSalesAmt(); //doesn't display newly entered monthly sales.
		}
	}
	return 0;
}
int getSalesAmt()
{
	int salesAmt;

	cout << "Enter a monthly sales amount: ";
	cin >> salesAmt;

	return salesAmt;
} 
float calcCommission(float commission, int salesAmt)
{
	float commission;

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

	return commission;
} 
float calcPay(float commission)
{
	float totalPay;

	//basePay = commission * salesAmt;

	return totalPay;
}
void displayPay(int salesAmt, float commission, float basePay, float totalPay)
{
	//cout << fixed << setprecision(1) << showpoint << 
	cout << "\nMonthly Sales:   $" << fixed << setprecision(2) << showpoint << salesAmt << endl;
	cout << "\nCommission:      $" << fixed << setprecision(2) << showpoint << commission << endl;
	cout << "\nBase Pay:        $" << fixed << setprecision(2) << showpoint << basePay << endl;
	cout << "\nTotal Pay:       $" << fixed << setprecision(2) << showpoint << totalPay << endl << endl;
}
My while loop doesn't seem to work how I wanted it to. Anyone able to help?
Line 27: Look at the difference here with line 16. How is the variable salesAmt getting updated at line 27?
Line 27: So it should look like this getSalesAmt(salesAmt); ?
So it should look like this getSalesAmt(salesAmt); ?

No. getSalesAmt() does not take an argument.

AbstractionAnon wrote:

How is the variable salesAmt getting updated at line 27?

Hint: getSalesAmt() returns a new value, but you don't do anything with it. Consequently, salesAmt is not updated. This is why I asked you to look at line 16. Line 16 takes the return value from getSalesAmt() and stores it in salesAmt. Line 27 does not do that.
Okay I made some changes. Now the output doesnt output how I wanted it to. I made a copy of what this is currently outputting.

The errors warnings within the code, I also have no idea how to fix.
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
#include <iostream>				
#include <string>
#include <iomanip>
using namespace std;

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

int main()
{
	int salesAmt;

	char answer = 'Y';
	salesAmt = getSalesAmt();

	while (toupper(answer) == 'Y')
	{
		int displayPay(); // What do I put here to make it display the Pay output?

		cout << "Do it again (Y or N)?  ";
		cin >> answer;

		if (toupper(answer) == 'Y')
		{
			salesAmt = getSalesAmt(); //doesn't display newly entered monthly sales.
		}
	}
	return 0;
}
int getSalesAmt()
{
	int salesAmt;

	cout << "Enter a monthly sales amount: ";
	cin >> salesAmt;

	return salesAmt;
} 
float calcCommission(float commission, int salesAmt)
{
	float commission; // error C2082: redefinition of formal parameter 'commission'

	if (salesAmt >= 50000)
	{
		commission = .02; // warning C4305: '=' : truncation from 'double' to 'float'
	}
	if (salesAmt >= 25000 & salesAmt <= 50000) // warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence
	{
		commission = .015; // warning C4305: '=' : truncation from 'double' to 'float'
	}
	else
	{
		commission = 0;
	}

	return commission;
} 
float calcPay(float commission)
{
	float totalPay;

	//basePay = commission * salesAmt;

	return totalPay; // warning C4700: uninitialized local variable 'totalPay' used
}
void displayPay(int salesAmt, float commission, float basePay, float totalPay)
{
	//cout << fixed << setprecision(1) << showpoint << 
	cout << "\nMonthly Sales:   $" << fixed << setprecision(2) << showpoint << salesAmt << endl;
	cout << "\nCommission:      $" << fixed << setprecision(2) << showpoint << commission << endl;
	cout << "\nBase Pay:        $" << fixed << setprecision(2) << showpoint << basePay << endl;
	cout << "\nTotal Pay:       $" << fixed << setprecision(2) << showpoint << totalPay << endl << endl;
}

/*Output
Enter a monthly sales amount: 66
Do it again (Y or N)?  y
Enter a monthly sales amount: 77
Do it again (Y or N)?  y
Enter a monthly sales amount: 88
Do it again (Y or N)?  n
Press any key to continue . . .*/
Line 20 is a function prototype, not a function call.

Note that the protoype and implementation of display_pay() require four arguments.

Line 43: You have two variables named commission. One is an argument, one is a local variable. Since you're setting and returning it, there doesn;t appear to be any reason to be passing it in as an argument.

Lines 47,51: The right side is implictly a double. To avoid the error, you can change the type of commission to double, or you can cast the right side as a float.

Line 66: Exactly what value do you think is being returned?
hint: garbage. You never stored anything in totalPay.
Last edited on
I couldn't figure it out in time. Got an F :(

I still don't know how to complete this.
Last edited on
Topic archived. No new replies allowed.