commission program

Suppose you are a salesman, selling widgets, working on a commission.
Your company pays you monthly commission according to the following:
For the first 10 widgets you sell, there's no commission
For the next 40 widgets you sell, you get $1 per widget
For the next 50 widgets you sell, you get $2 per widget
For the next 100 widgets you sell, you get $5 per widget
For any widgets you sell after that, you get $3 per widget

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  if ( widgets <= 10 )
		com = widgets * 0;
		cout << "Commission: " << "$" << com << endl;
	if ( widgets >= 11 && widgets <= 40)
		com = widgets * 1;
		cout << "Commission: " << "$" << com << endl;
	if ( widgets >= 41 && widgets <= 50 )
		com = widgets * 2;
		cout << "Commission: " <<"$" << com << endl;
	if ( widgets  >= 51 && widgets <= 100 )
		com = widgets * 5;
		cout << "Commission: " << "$" << com <<endl;
	if ( widgets > 100)
		com = widgets * 3;
		cout << "Commission: " << "$" << com << endl;


I don't understand why the example say if you input 200 you gonna get 640

another one 1000200 you get 3000640
See, you are selling a total of 200 widgets.

After selling the 1st 10 widgets,
Commission = 0
Widgets remaining = 200 - 10 = 190

After selling the next 40 widgets,
Commission = 0 + 1 * 40 = 40
Widgets remaining = 190 - 40 = 150

After selling the next 50 widgets,
Commission = 40 + 2 * 50 = 40 + 100 = 140
Widgets remaining = 150 - 50 = 100

After selling the next 100 widgets,
Commission = 140 + 5 * 100 = 140 + 500 = 640
Widgets remaining = 100 - 100 = 0

Hence, you get $ 640 as commission. For the other input, proceed as illustrated above and you'll figure it out ;)

Hope that helped.

thank you, but

it didn't work for other one 1000200

Topic archived. No new replies allowed.