14 Replies - 9482 Views - Last Post: 24 January 2010 - 09:41 AM Rate Topic: -----

#1 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Payroll Pseudo Code

Posted 24 January 2010 - 07:18 AM

Each week we must complete a code and build on it. This is what I completed for last week.
Do While More Records
	 Get name, hours, payrate
	 If hours>40
		  Basepay=40*payrate
		  Base=40
		  Overhours=hours-40
		  Overtime=Overhours*payrate*1.5
	 Else
		  Basepay=hours*payrate
		  Base=hours
		  Overtime=0
		  Overhours=0
	 Endif
	 Grosspay=Basepay+Overtime
	 Display name, basepay, overhours, overtime, grosspay
End Do


This week we need to calculate withholdings for each employee paycheck. There are three that must be calculated: State Tax 6%, Federal Tax 15% and Social Security at 7.5%. Add this processing to your pseudo code. Add each tax amount in the output, a total withholding and a gross pay and net pay amount. I need some help getting started.

*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 24 January 2010 - 07:24 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Payroll Pseudo Code

#2 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5959
  • View blog
  • Posts: 23,229
  • Joined: 23-August 08

Re: Payroll Pseudo Code

Posted 24 January 2010 - 07:25 AM

Well, all those are calculated off of the gross pay, so that should get you started. And seeing as this is not C or C++ but pseudocode, I moved this to Other Languages.
Was This Post Helpful? 0
  • +
  • -

#3 AverageGuy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 23-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 07:29 AM

View Postlobermire, on 24 Jan, 2010 - 06:18 AM, said:

Each week we must complete a code and build on it. This is what I completed for last week.
Do While More Records
	 Get name, hours, payrate
	 If hours>40
		  Basepay=40*payrate
		  Base=40
		  Overhours=hours-40
		  Overtime=Overhours*payrate*1.5
	 Else
		  Basepay=hours*payrate
		  Base=hours
		  Overtime=0
		  Overhours=0
	 Endif
	 Grosspay=Basepay+Overtime
	 Display name, basepay, overhours, overtime, grosspay
End Do

This week we need to calculate withholdings for each employee paycheck. There are three that must be calculated: State Tax 6%, Federal Tax 15% and Social Security at 7.5%. Add this processing to your pseudo code. Add each tax amount in the output, a total withholding and a gross pay and net pay amount.  I need some help getting started.

*** MOD EDIT: Added code tags. Please :code: ***




After calculating the grosspay, initialize a total taxes variable (to 0). Then calculate each tax and add it to the total. Then calculate the net income by subtracting the total taxes from the gross.

Jim.
Was This Post Helpful? 0
  • +
  • -

#4 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 07:55 AM

View PostAverageGuy, on 24 Jan, 2010 - 06:29 AM, said:

View Postlobermire, on 24 Jan, 2010 - 06:18 AM, said:

Each week we must complete a code and build on it. This is what I completed for last week.
Do While More Records
	 Get name, hours, payrate
	 If hours>40
		  Basepay=40*payrate
		  Base=40
		  Overhours=hours-40
		  Overtime=Overhours*payrate*1.5
	 Else
		  Basepay=hours*payrate
		  Base=hours
		  Overtime=0
		  Overhours=0
	 Endif
	 Grosspay=Basepay+Overtime
	 Display name, basepay, overhours, overtime, grosspay
End Do

This week we need to calculate withholdings for each employee paycheck. There are three that must be calculated: State Tax 6%, Federal Tax 15% and Social Security at 7.5%. Add this processing to your pseudo code. Add each tax amount in the output, a total withholding and a gross pay and net pay amount.  I need some help getting started.

*** MOD EDIT: Added code tags. Please :code: ***




After calculating the grosspay, initialize a total taxes variable (to 0). Then calculate each tax and add it to the total. Then calculate the net income by subtracting the total taxes from the gross.

Jim.


This is what I have so far but am not sure I am on the right track.

Do While More Records
Get name, grosspay
Grosspay*6% state tax
Grosspay *15% federal tax
Grosspay*7.5% social security tax
Else
State tax+Federal tax+Social Secuirty tax=total taxes withheld
Grosspay+total taxes withheld =gross pay
State tax=0
Federal tax=0
Social Security tax=0
Endif
net pay=grosspay-total taxes withheld
Dispaly name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay
Was This Post Helpful? 0
  • +
  • -

#5 AverageGuy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 23-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 08:07 AM

View Postlobermire, on 24 Jan, 2010 - 06:55 AM, said:

This is what I have so far but am not sure I am on the right track.

Do While More Records
Get name, grosspay
Grosspay*6% state tax
Grosspay *15% federal tax
Grosspay*7.5% social security tax
Else
State tax+Federal tax+Social Secuirty tax=total taxes withheld
Grosspay+total taxes withheld =gross pay
State tax=0
Federal tax=0
Social Security tax=0
Endif
net pay=grosspay-total taxes withheld
Dispaly name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay

No, not gonna work. It makes no sense. You need an IF to use ELSE and ENDIF.
So remove the else and endif. The gross pay stays the same, don't add the taxes back in. Add an endWhile at the end of it all. And you should be consistant in your psuedo code. It's conventional to have the assignment go from right to left. E. g.
State tax+Federal tax+Social Secuirty tax=total taxes withheld


should be
total taxes=State tax+Federal tax+Social Secuirty taxes 


You're doing it both ways in your example.

Jim.
Was This Post Helpful? 0
  • +
  • -

#6 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 08:18 AM

Okay, here is another try based off of your comments.

Do While More Records
Get name, gross pay
Gross pay*6% state tax
Gross pay*15% federal tax
Gross pay*7.5% Social Security tax

total taxes withheld=state tax+federal tax+social security tax
State ax=0
Federal tax=0
Social Security=0
net pay=gross pay-total taxes withheld
Display name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay

endWhile
Was This Post Helpful? 0
  • +
  • -

#7 AverageGuy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 23-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 08:24 AM

View Postlobermire, on 24 Jan, 2010 - 07:18 AM, said:

Gross pay*6% state tax
Gross pay*15% federal tax
Gross pay*7.5% Social Security tax

I'd suggest improving on those three lines. They don't make sense in even psuedo code.

use
aaa = bbb
Like you did later. And be sure to zero out the total taxes and you don't have to zero out each tax.
In addition I'd put the totaltax=0 just after the while.
Jim.

This post has been edited by AverageGuy: 24 January 2010 - 08:26 AM

Was This Post Helpful? 0
  • +
  • -

#8 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 08:27 AM

View PostAverageGuy, on 24 Jan, 2010 - 07:24 AM, said:

View Postlobermire, on 24 Jan, 2010 - 07:18 AM, said:

Gross pay*6% state tax
Gross pay*15% federal tax
Gross pay*7.5% Social Security tax

I'd suggest improving on those three lines. They don't make sense in even psuedo code.

use
aaa = bbb
Like you did later. And be sure to zero out the total taxes and you don't have to zero out each tax.
In addition I'd put the totaltax=0 just after the while.
Jim.



Jim,
Not sure how to improve those three lines. Can you show me how to adjust one of those lines. I will zero out the total tax instead of all three.
Was This Post Helpful? 0
  • +
  • -

#9 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 08:34 AM

View Postlobermire, on 24 Jan, 2010 - 07:27 AM, said:

View PostAverageGuy, on 24 Jan, 2010 - 07:24 AM, said:

View Postlobermire, on 24 Jan, 2010 - 07:18 AM, said:

Gross pay*6% state tax
Gross pay*15% federal tax
Gross pay*7.5% Social Security tax

I'd suggest improving on those three lines. They don't make sense in even psuedo code.

use
aaa = bbb
Like you did later. And be sure to zero out the total taxes and you don't have to zero out each tax.
In addition I'd put the totaltax=0 just after the while.
Jim.



Jim,
Not sure how to improve those three lines. Can you show me how to adjust one of those lines. I will zero out the total tax instead of all three.



Should it be:

Gross pay*.006 state tax
Gross pay*.15 federal tax
Gross pay*.075 social security tax
Was This Post Helpful? 0
  • +
  • -

#10 AverageGuy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 23-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 08:36 AM

View Postlobermire, on 24 Jan, 2010 - 07:27 AM, said:

View PostAverageGuy, on 24 Jan, 2010 - 07:24 AM, said:

View Postlobermire, on 24 Jan, 2010 - 07:18 AM, said:

Gross pay*6% state tax
Gross pay*15% federal tax
Gross pay*7.5% Social Security tax

I'd suggest improving on those three lines. They don't make sense in even psuedo code.

use
aaa = bbb
Like you did later. And be sure to zero out the total taxes and you don't have to zero out each tax.
In addition I'd put the totaltax=0 just after the while.
Jim.



Jim,
Not sure how to improve those three lines. Can you show me how to adjust one of those lines. I will zero out the total tax instead of all three.

OK, look at this
  1 Do While More Records
  2 Get name, gross pay
  3 Gross pay*6% state tax
  4 Gross pay*15% federal tax
  5 Gross pay*7.5% Social Security tax
  6
  7 total taxes withheld=state tax+federal tax+social security tax
  8 State ax=0
  9 Federal tax=0
 10 Social Security=0
 11 net pay=gross pay-total taxes withheld
 12 Display name, state tax, federal tax, social security tax, total taxes withheld, gros	s pay and net pay
 13
 14 endWhile



Now compare lines 7, 8, 9, 10 and 11 to lines 3, 4 and 5.. Do you see a difference?
In one case (11), you are saying "Set netpay to the difference of grosspay and total taxes". In line 3, well it doesn't say anything. There is no = sign. And if there was, it would read backwards.

Jim
Was This Post Helpful? 0
  • +
  • -

#11 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 08:46 AM

Okay, I feel like I am becoming more confused. Here is another shot

Do While More Records
Get name, gross pay
Total Taxes Withheld=0
Gross pay=gross pay* .006 state tax*.15 federal tax*.075 social security tax
Total taxes withheld=state+federal+social security
net pay=gross pay-total taxes withheld
Display name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay
endWhile
Was This Post Helpful? 0
  • +
  • -

#12 AverageGuy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 23-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 09:04 AM

View Postlobermire, on 24 Jan, 2010 - 07:46 AM, said:

Okay, I feel like I am becoming more confused. Here is another shot

Do While More Records
Get name, gross pay
Total Taxes Withheld=0
Gross pay=gross pay* .006 state tax*.15 federal tax*.075 social security tax
Total taxes withheld=state+federal+social security
net pay=gross pay-total taxes withheld
Display name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay
endWhile

Not yet. Think about it this way. How would you calculat this by hand using a caclulator or heaven forbid a pencil and brain?

One way would be to take a piece of paper and draw columns, like Name, Gross Pay,Federa Tax, State Tax, SocSec Tax, Total Tax, Net Pay.
And start writing the name and gross pay on the first line. Now how would you determine the federal tax? You'd multiply the gross pay by the tax rate. Then you'd write it in the Federa Tax column. Right?
In a computer language you have variables instead of columns. So you'd write that number you just calculated into a variable with what's called a variable assignment, or something like
FedTax = Gross*TaxRate
You aren't doing that. You're clobbering your gross pay. You should not write over the gross pay except when you calculate it, back in your previous assignment.

If this isn't clear, take an example and put a name in column 1, an amount in column 2, calculate the rest of the columns. As you do each step on a separate piece of paper write in english exactly what you did.
For example
Step 1 entered name in name column
Step 2 entered gross pay in gross pay column
Step 3 multiplied gross pay by fed tax rate
Step 4 entered step 3 result in fed tax column
Step 5 multiplied gross pay by state tax rate
Step 6 entered step5 result in state tax collumn
etc.

Those are pretty much a description of what you will do in pseudo code. Where "entered" is equivalent to the assignment operator or
FedTax = Gross*TaxRate

Did that help?

Jim
Was This Post Helpful? 0
  • +
  • -

#13 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 09:16 AM

I think I am getting there. Thank you for being soo patient. I have only been learning this for three weeks.

Do While More Records
Get name, gross pay
Total Taxes=0
Federal Tax=gross pay*.15
State Tax=gross pay*.006
Social Security Tax=.075
Total taxes withheld=state+federal+social security

Net pay=gross pay-total taxes withheld
Display name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay

endWhile

View Postlobermire, on 24 Jan, 2010 - 08:13 AM, said:

I think I am getting there. Thank you for being soo patient. I have only been learning this for three weeks.

Do While More Records
Get name, gross pay
Total Taxes=0
Federal Tax=gross pay*.15
State Tax=gross pay*.006
Social Security Tax=gross pay*.075
Total taxes withheld=state+federal+social security

Net pay=gross pay-total taxes withheld
Display name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay

endWhile

Was This Post Helpful? 0
  • +
  • -

#14 AverageGuy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 23-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 09:19 AM

View Postlobermire, on 24 Jan, 2010 - 08:16 AM, said:

I think I am getting there. Thank you for being soo patient. I have only been learning this for three weeks.

Do While More Records
Get name, gross pay
Total Taxes=0
Federal Tax=gross pay*.15
State Tax=gross pay*.006
Social Security Tax=.075
Total taxes withheld=state+federal+social security

Net pay=gross pay-total taxes withheld
Display name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay

endWhile

View Postlobermire, on 24 Jan, 2010 - 08:13 AM, said:

I think I am getting there. Thank you for being soo patient. I have only been learning this for three weeks.

Do While More Records
Get name, gross pay
Total Taxes=0
Federal Tax=gross pay*.15
State Tax=gross pay*.006
Social Security Tax=gross pay*.075
Total taxes withheld=state+federal+social security

Net pay=gross pay-total taxes withheld
Display name, state tax, federal tax, social security tax, total taxes withheld, gross pay and net pay

endWhile

OK except you do need to be consistant in your naming. Note that you use "Total Taxes" in one place and "Total taxes withheld" in another. They are the same.

Good work. If you get stumped in the future, use the paper and pencil method to understand the steps need to get toi where ypu want to be. Then take the steps and translate them into pseudo code.

Good luck

Jim
Was This Post Helpful? 0
  • +
  • -

#15 lobermire  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-January 10

Re: Payroll Pseudo Code

Posted 24 January 2010 - 09:41 AM

Thank you very, very much for all of your help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1