+ 3

How to write a commission program using only loops (while, for, do, etc.) and no “if or else statements.”

I’m really stuck on this assignment my professor has given me lately. We have to write a program that calculates how much money will a vendor receive depending on how many articles he has sold within a week. v = sales in articles salary = weekly salary p = commission percentage - $000 - $500 = p = 0.0 $500 - $1500 = p = 5.0 $1500 - $3000 = p = 7.5 $3000 - $5000 = p = 10.0 $5000 + = p = 12.0 com = commision money = v * (p / 100.0) total = total amount of money the vendor will receive = com + salary

28th May 2018, 1:10 AM
Andy Cruz
Andy Cruz - avatar
5 Respostas
+ 6
One while loop and (two arrays) or one (two-dimensional array) should do.
28th May 2018, 5:55 AM
ODLNT
ODLNT - avatar
+ 2
I don’t think so. We haven’t reached that discussion yet. We’ve mostly talked about how brackets change the way a loop is determined by the values that it has within.
28th May 2018, 3:51 AM
Andy Cruz
Andy Cruz - avatar
0
This should get you started, I think. ______________________________ #include <aheader> int v, com, salary, p, total; #include <settingthesevariables> int table1 (int); main () { cin >> artsold; #include <otherpromptsifyoufeelfancy> v = table1 (artsold); #include <math> cout << total return 0; } table1 (int n) { int foo; while (x<100) while (x<150) { while (x<200) { foo = bar; return foo; } foo = baz; return foo; } foo = qux return foo } exit }
30th May 2018, 10:51 AM
Chuck D
Chuck D - avatar
0
The idea is nested whiles first, then once the process has gone as far as n/artsold will allow, return a value to main (and thus exit the loop). My step of assigning a variable then returning that variable is actually not necessary but could maybe make debugging easier.
30th May 2018, 10:55 AM
Chuck D
Chuck D - avatar