Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,926 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,823 people online right now. Registration is fast and FREE... Join Now!




payroll (please help)

 
Reply to this topicStart new topic

payroll (please help)

c++izhere
16 Mar, 2008 - 07:47 PM
Post #1

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
using c++ develop a program for the ABC company whose salespeople are paid both a base salary and a commission. Input to the program is sales person's first and last names and weekly sales. Output is the salesperson's first initial, and full last name and correct pay. Pay is calculated as follows. Each salesperson receives a base pay of $300.00 as well as a 10% commission on sales up to and including $500.00. Any portion of sales over 500 merits a 15% commission for the employee


cpp
														
#include<iostream>

int main()

{
double com1, com2;
char fName[20];
char lName[20];
double sales;
double cpay;
double tpay, tpay2;
double bpay;


bpay= 300.00;
com1= sales * .10;
com2= sales * .15;
tpay= (bpay+com1);
tpay2= (bpay+com2);

std::cout<< "Please Enter First and Last Name"<<std::endl;
std::cin>>fName>>lName;
std::cout<< "Enter Sales"<<std::endl;
std::cin>>sales;

{

if ( sales <= 500)

std::cout<<fName[0]<< " " <<lName<<std::endl;
std::cout<<tpay<<std::endl;

else if ( sales >500)

std::cout<<tpay2+com2<<endl;

}


return 0;

}

*edit: Fixed your code tags. Remember they surround your code. smile.gif

This post has been edited by Martyr2: 16 Mar, 2008 - 07:52 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Payroll (please Help)
16 Mar, 2008 - 08:07 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,231



Thanked: 220 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Not too bad but remember that you must ask for information before you can go using it in calculations. You can't use sales variable before you asked the user for it. So I switched the input and the calculations around.

Keep in mind (like mentioned in the in-code comments) that the 15% only applies to the dollars over the 500 mark. You get 10% on the first 500 and anything over 500 is at 15%. Not 15% of the total sales amount.

cpp

#include<iostream>

int main()
{
double com1, com2;
char fName[20];
char lName[20];
double sales;
double cpay;
double tpay, tpay2;
double bpay;

// Prompt for the data first from the user before attempting
// to use variables like "sales" in calculations.
// How can you use sales when you hadn't asked for it yet?
std::cout<< "Please Enter First and Last Name"<<std::endl;
std::cin>>fName>>lName;
std::cout<< "Enter Sales"<<std::endl;
std::cin>>sales;

// Good start, but remember the 15% applies to any
// value OVER the initial 500, not the total sales.
// eg 600 in sales is 10% of 500 or $50 but then 15% of 100
// (600 - 500 = 100 which is what part is over 500).
// answer: 300 base + 50 (10% of 500) + 15 (15% of 100 over 500) = $365.00
bpay= 300.00;
com1= sales * .10;
com2= sales * .15;
tpay= (bpay+com1);
tpay2= (bpay+com2);

// Fixed up your curly braces here.
// It is good practice to always include curly braces.
if (sales <= 500) {
std::cout << fName[0] << " " << lName << std::endl;
std::cout << tpay << std::endl;
}

else if (sales > 500) {
std::cout << tpay2+com2 << std::endl;
}

return 0;
}


Here is your program with a bit more fixing. I left the calculation of the 15% up to you. I provided an example to help you out with that though.

Oh and make sure to print their name for when they have sales over 500.

It should be a snap now. Enjoy!

"At DIC we be percentage commission code ninjas! But we be ninjas with bling bling because we have high sales!" decap.gif

This post has been edited by Martyr2: 16 Mar, 2008 - 08:08 PM
User is online!Profile CardPM
+Quote Post

c++izhere
RE: Payroll (please Help)
16 Mar, 2008 - 08:23 PM
Post #3

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
[thanks man for everything. the only thing is when i run this program it ends right after i input the sales...im using bloodshed dev c++ 4.9.9.2
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Payroll (please Help)
16 Mar, 2008 - 08:25 PM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,231



Thanked: 220 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
If you mean that the program simply ends, try holding open the window using something like getchar() at the end. It might be doing your calculation real fast and closing the program.

smile.gif
User is online!Profile CardPM
+Quote Post

c++izhere
RE: Payroll (please Help)
16 Mar, 2008 - 08:30 PM
Post #5

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
QUOTE(Martyr2 @ 16 Mar, 2008 - 09:25 PM) *

If you mean that the program simply ends, try holding open the window using something like getchar() at the end. It might be doing your calculation real fast and closing the program.

smile.gif


put it like this at the end before return 0;

getchar();



ps. i'm a little confused about the calculations

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Payroll (please Help)
16 Mar, 2008 - 08:33 PM
Post #6

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,231



Thanked: 220 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You can't be too confused, you are on the right track. Just remember that if the sales is less than 500, you apply 10% to it. If it is greater than 500 you apply 10% to the 500 and then 15% to the total sales minus the 500.

smile.gif
User is online!Profile CardPM
+Quote Post

c++izhere
RE: Payroll (please Help)
16 Mar, 2008 - 08:38 PM
Post #7

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
QUOTE(Martyr2 @ 16 Mar, 2008 - 09:33 PM) *

You can't be too confused, you are on the right track. Just remember that if the sales is less than 500, you apply 10% to it. If it is greater than 500 you apply 10% to the 500 and then 15% to the total sales minus the 500.

smile.gif


so now it should be...

else if (sales >500)

std::cout<<tpay+com1+com2<<std::endl;
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Payroll (please Help)
16 Mar, 2008 - 08:42 PM
Post #8

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,231



Thanked: 220 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
No take the total sales and if it is greater than 500 subtract the 500 and times the remainder by the 15%.

cpp


if (sales > 500) {
// 300 base pay + 10% on the first 500 (aka $50) + the sales minus
// the first 500 and times that by the 15%

// eg 600 sales = 300 base pay + $50 + (600-500 = 100 * .15 = $15)
tpay = 300 + (.10 * 500) + ((sales - 500) * .15)
}


wink2.gif
User is online!Profile CardPM
+Quote Post

c++izhere
RE: Payroll (please Help)
16 Mar, 2008 - 08:46 PM
Post #9

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
thanks bro..appreciate it...

1 more thing do you how to stop this program from ending so quickly

i put in the getchar() but its still closing
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Payroll (please Help)
16 Mar, 2008 - 08:52 PM
Post #10

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,231



Thanked: 220 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
The getchar() at the end before the return 0 should pause your program (waiting for input) and thus should not close. Make sure you are also running the program in a debug mode which may help keep it open.

I have seen other people ask about it in Bloodshed Dev and that is what they are using is the getchar().

If that doesn't work, you could try system("pause"); which should work if you are on a windows machine.
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:24PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month