#include %26lt;iostream.h%26gt;
#include %26lt;stdio.h%26gt;
int main ()
{
int regular pay, total sales, commission, total pay;
printf(" enter your regular pay\n");
scanf("%d", %26amp;regular pay);
printf("enter total sales\n");
scanf("%d", %26amp;total sales);
commission = total sales * 9 / 100;
printf("commission is %d\n");
total pay= commission + regular pay;
printf("your total pay is %d\n");
system ("pause");
return 0;
}
the question is:
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 ernings. Process one sales person's figures at a time.
Can someone please help me with my c program!?
FIRST OFF, i admire your ability to say please. It's only cowardly, insecure, prideful men who cannot say please for fear of looking weak. The bigger man is never afraid to say please, and i salute you for being a man who stands above them.
1. You want to use type float for money...then you can get the
decimal. Example:
float commission;
commission = total_sales * 9.0 / 100.0;
printf("commission is $%0.2f\n",commission);
So, if commission was $25.59, then it should say so, not "$25"
2. The assignment says "Process one sales person's figures at a time." The hint here is that there's more than one person, so I recommend usage of a loop since your instructor/boss may be looking for it.
int done = 0;
do{
printf(" enter your regular pay\n");
scanf("%d", ®ular pay);
...
...
if(some-condition-says-we're-done)
done = 1;
}while(!done);
...there are some more problems in your code, but let's let someone else have a shout.
Reply:Well first, your code is wrong. Variables can't have spaces. You need to have regular_pay or regularPay as your variables.
Next, you don't have to have the user input regular pay since it is a constant $200. Setup a constant variable to hold this
#define PAY 200 after the include statements or const int PAY = 200 at the beginning of the main function.
Next, if you want to do this for multiple people, you need to setup a for loop if you want a set number of people to calcuate pay for, or a do/while loop if you have a dinamic number of sales persons.
something like this:
do
get sales
calculate totalPay
Display totalPay
Ask user if they want to enter another sales persons (Store in bool variable 'Another')
while (Another)
You could also store the totalPay in an array. and just add to it as you enter more sales people's totalPay, then setup a forloop to display all people and their pay, but for this, you might want the prompt the user for a name for each of the sales people.
Reply:It is not C if you include iostream.h
In C++, this is how you could code your program.
#include %26lt;iostream.h%26gt;
int main ()
{
const double regular_pay = 200.0;
double total_sales, commission, total_pay;
char ans;
do {
cout %26lt;%26lt; "Enter total sales $";
cin %26gt;%26gt; total_sales;
commission = total_sales * 9.0 / 100;
cout %26lt;%26lt; "Commission is $" %26lt;%26lt; commission %26lt;%26lt; endl;
total_pay = commission + regular_pay;
cout %26lt;%26lt; "Your total pay is $" %26lt;%26lt; total_pay %26lt;%26lt; endl %26lt;%26lt; endl;
cout %26lt;%26lt; "Do another salesperson ? "
cin %26gt;%26gt; ans;
} while (ans == 'Y' || ans == 'y');
return 0;
}
As C code.
#include %26lt;stdio.h%26gt;
int main ()
{
const double regular_pay = 200.0;
double total_sales, commission, total_pay;
char ans;
do {
printf("Enter total sales $");
scanf("%lf", %26amp;total_sales);
commission = total_sales * 9.0 / 100;
printf("Commission is $%0.2lf\n", commission);
total_pay = commission + regular_pay;
printf("Your total pay is $%0.2lf\n\n", total_pay);
printf("Do another salesperson ? ");
fflush(stdin);
ans = getchar();
fflush(stdin);
} while (ans == 'Y' || ans == 'y');
return 0;
}
Hope this helps.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment