This seems like a homework problem. So lets think it out rationally. There's a large chemical company that pays people on commission. Okay, so that means that the employees are going to earn a portion of their sales. Now we read the sales people receive $200/week plus 9% of their gross sale. Well, calculating 9% is the same as multiplying gross sale by 0.09. And then we add that to $200/week to calculate the amount per salesperson.
So now it says use a while structure to input each salesperson's gross sales and calculate and display that salesperson's earnings. So we can use the following algorithm:
LOOP:
Ask for salesperson's gross sale
Calculate 9% of their gross sale and put it in a variable such as "wage"
Add 200 to the "wage" variable since all employees get at least that
Print out the "wage" variable
Loop again for the next salesperson
Remember, you're going to need some way to get the while loop to stop. For example, you can set it so that the while loop will loop so long as a value greater than 0 is entered for a gross sale. But if 0 or a negative value is entered, the loop stops and the program ends.
See if you can come up with some C++ code using this algorithm and then we'll be glad to help you more. However, we have a policy on these forums(and almost all other programming forums on the web) where we will HELP you with your homework but won't do it for you.
cscgal
The Queen of DaniWeb
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
Hello Peter,
Couple things that I see that need help on....
1. When you declare the variable (numsales), it is a good idea to initialize it manually before starting to use it. Some compilers may assign a goofy number to the new variable. So, after your init numsales; I would have a numsales = 0;
2. If you put the program into a compiler, and tried to compile it, the program would error. You are missing syntax... take a look at how the while is to be written. You also forgot to declare numcommission.
3. You tried to use numsales as an integer, but compare it to a real (1.0 is a real number). This is a problem. Reference the 1 as an integer. 1.
4. cin >> numsales is the proper way to enter in the variable.
5. Be careful on operator precidence. Let me explain.... if you do multiplication and addition:
(3 + 4) * 10 = 70
3 + 4 * 10 = 43
3 + (4 * 10) = 43
I would have written numcom = ((numsales * 0.09) + 200) note that the compiler will bomb out with the $200;
Also, I noticed you had very few comments. Teachers (and employers) really love comments. Put them into your code!
Take care,
Christian
kc0arf
Posting Virtuoso
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
Please dont bump old threads, post your problem in a new thread. Thread closed.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733