# Redo calculate pay to check for overtime

Page 1 of 1

## 5 Replies - 3298 Views - Last Post: 18 October 2010 - 01:53 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=195558&amp;s=c3300fb301a720f610dc5f4cf768e5fe&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 TOKYO64

Reputation: 0
• Posts: 15
• Joined: 18-October 10

# Redo calculate pay to check for overtime

Posted 18 October 2010 - 07:20 AM

My assignment is to redo the calculate pay to check for overtime. Of course any hours over 40 are paid at time and 1/2. We have deductions too but I've already worked them out. The only thing I haven't figured out is how to do the calculate pay to check for overtime. Here is what I have so far:

```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignement3D
{
class Program
{
double grossPay;

static void Main(string[] args)
{
//Anthony Berry
//* 10/15/2010
//* Assignment 3
// * */
Program prog = new Program();
prog.GetNumbers();
}
void CalculateGross(double rt, double hrs)
{
grossPay = hrs * rt;
}
void GetNumbers()
{
Console.WriteLine("Enter the Rate");
Console.WriteLine("Enter the Hours");
Console.WriteLine("The Gross pay is {0}", grossPay.ToString("c"));
CalculateGross(rate, hours);
CalculateTotalDeductions();
CalculateTotalNetPay();

}

double socialSecurity()
{
//at or above 5000 30%
// at or above 3000 25%
//at or above 2000 20%
//at or above 1000 15%
//at or above 800 10%
//below 800 0%
double socialSecurity;
if (grossPay >= 5000)
{
socialSecurity = grossPay * .3;
}
else if (grossPay >= 3000)
{
socialSecurity = grossPay * .25;
}
else if (grossPay >= 2000)
{
socialSecurity = grossPay * .2;
}
else if (grossPay >= 1000)
{
socialSecurity = grossPay * .1;
}
else if (grossPay >= 800)
{
socialSecurity = grossPay * .1;
}
else
{
socialSecurity = 0;
}
return socialSecurity;

}
double healthInsurance()
{
//at above 2000 50
//at or below 2000 25
double healthInsurance;
if (grossPay > 2000)
{
healthInsurance = -50;
}
else if (grossPay <= 2000)
{
healthInsurance = -25;
}
else
{
healthInsurance = 0;
}
return healthInsurance;
}

double medicare()
{
//at or above 3000 8%
//at or above 1000 5%
//at or above 800  2.5%
//below 800 0%
double medicare;
if (grossPay >= 3000)
{
medicare = grossPay * .08;
}
else if (grossPay >= 1000)
{
medicare = grossPay * .05;
}
else if (grossPay >= 800)
{
medicare = grossPay * .025;
}
else
{
medicare = 0;
}
return medicare;

}
void CalculateTotalDeductions()
{
double hi = healthInsurance();
double ss = socialSecurity();
double md = medicare();
double totalDeductions = ss + md + hi;
Console.WriteLine("The Total Deductions are {0}", totalDeductions.ToString("c"));
Console.WriteLine("The Social Security Deduction is {0}", ss.ToString("c"));
Console.WriteLine("The Health Insurance Deduction is {0}", hi.ToString("c"));
Console.WriteLine("The Medicare Deduction are {0}", md.ToString("c"));
}
void CalculateTotalNetPay()
{
double hit = healthInsurance();
double sst = socialSecurity();
double mt = medicare();
double totalDeductions = sst + mt + hit;
double gp = grossPay;
double np = grossPay - totalDeductions;
Console.WriteLine("The Net pay is {0}", np.ToString("c"));

}//class

}
}
```

MOD EDIT: When posting code...USE CODE TAGS!!!

This post has been edited by JackOfAllTrades: 18 October 2010 - 07:33 AM

Is This A Good Question/Topic? 0

## Replies To: Redo calculate pay to check for overtime

### #2 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5106
• Posts: 9,283
• Joined: 08-June 10

## Re: Redo calculate pay to check for overtime

Posted 18 October 2010 - 07:34 AM

Second, you don't need to instantiate your Program class if you make the methods static.

Third, consistency is key. Don't mix and match the case of your method names. Here's a great link on naming guidelines:
http://msdn.microsof...y/ms229002.aspx

There's nothing special about overtime calculation. Let's think of the math here:
From 0 - 40 hours, the rate is X.
Greater than 40, the rate is X * 1.5.

So (pseudocode)
```IF total GREATER THAN 40 THEN
normal = 40
overtime = total - 40
ELSE
normal = total
overtime = 0
gross = (overtime * rate * 1.5) + (normal * rate)
```

You should use constants instead of literals, but that's the basic idea without giving you code.

This post has been edited by insertAlias: 18 October 2010 - 10:34 AM

• Saucy!

Reputation: 6259
• Posts: 24,028
• Joined: 23-August 08

## Re: Redo calculate pay to check for overtime

Posted 18 October 2010 - 07:40 AM

How would you calculate it on paper?

### #4 eclipsed4utoo

Reputation: 1536
• Posts: 5,972
• Joined: 21-March 08

## Re: Redo calculate pay to check for overtime

Posted 18 October 2010 - 09:40 AM

insertAlias, on 18 October 2010 - 10:34 AM, said:

So (pseudocode)
```IF total GREATER THAN 40 THEN
normal = 40
overtime = total - 40
ELSE
normal = total
overtime = 40
gross = (overtime * rate * 1.5) + (normal * rate)
```

I think your pseudocode is wrong. In your else block, you are saying that if the hours is 30, then they would get 30 hours of normal pay AND 40 hours of overtime pay.

I think it should be this...

```IF total GREATER THAN 40 THEN
normal = 40
overtime = total - 40
ELSE
normal = total
overtime = 0
gross = (overtime * rate * 1.5) + (normal * rate)

```

### #5 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5106
• Posts: 9,283
• Joined: 08-June 10

## Re: Redo calculate pay to check for overtime

Posted 18 October 2010 - 10:33 AM

It is wrong, I don't know why i added a 4 to that zero. Editing it now.

This post has been edited by insertAlias: 18 October 2010 - 10:34 AM

### #6 TOKYO64

Reputation: 0
• Posts: 15
• Joined: 18-October 10

## Re: Redo calculate pay to check for overtime

Posted 18 October 2010 - 01:53 PM

insertAlias, on 18 October 2010 - 09:33 AM, said:

It is wrong, I don't know why i added a 4 to that zero. Editing it now.

got it no problems. Thanks.