+ 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
5 Respostas
+ 6
One while loop and (two arrays) or one (two-dimensional array) should do.
+ 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.
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
}
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.