I'm new to the forum and new to coding (period.), and was looking for some help.
This question pops up alot around the web, but because C++ language a bit different from modern, in VS C++ 2008, i'm having a bit of trouble.
Question:
One large chemical company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of chemicals in a week receives $200 plus 9% of $5000, or a total of $650. Develop a program that will input each salesperson's gross sales for last week and will calculate and display that salesperson's earnings. Process one salesperson's figures at a time.
Here is a sample input/output dialog:
Enter sales in dollars (-1 to end): 5000.00
Salary is: $650.00
Enter sales in dollars (-1 to end): 1234.56
Salary is: $311.11
Enter sales in dollars (-1 to end): 1088.89
Salary is: $298.00
Enter sales in dollars (-1 to end): -1
//Sales Calculator Problem //
#include<stdio.h>
int main (void)
{
int base = 200;
double salary;
int week;
float sales;
double commission;
week = 1;
As a kind remark, please try to wrap your code in [ code ]-tags next time, it makes it more readable.
As to your problem, let's have a look at this while loop:
1 2 3 4 5 6 7 8 9 10
//begin loop while sentinel value not yet read //
while (sales != -1)
{
commission = 0.09 * sales;
salary = commission + base;
++week;
printf ("Salary is \n", salary);
}
You are telling the program to loop while the sales variable is not equal to minus one.
If you ever want to stop the loop, the sales variable will have to be set to minus one at some point, when you want to break the loop, or it will never change into -1, repeating the loop indefinitely.
Hope that gets you on your way, do let us know if you need any further help.
Thank you. I have made some revisions, but unable to run the program since i'm on a different computer. Does the "if" statement within the "while" suffice? Thanks again for your help.