• 0

C# Employee Gross Pay using While Loop


Question

Hi, This is a homework assignment I have been working on and have gotten stuck. This is what the assignment is:

 

Develop a C# console application that will determine the gross pay for each of three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40 hours. You are given a list of the three employees of the company, the number of hours each employee worked last week, and the hourly rate of each employee. Your application should input this information for each employee and should determine and display the employee

9 answers to this question

Recommended Posts

  • 0

As others already said, use Convert.ToDouble to solve the error while compiling.

 

I noticed a problem with your calculation when extra hours are involved:

  • First you need to calculate 40 hours multiplied by the regular hourly rate. These are the first 40 hours which should always be multiplied by the regular hourly rate.
  • Then add the result of the extra hours multiplied by the extra hourly rate.

Here's an example:

total = (40 * rate) + ((hours - 40) * (1.5 * rate));

This calculates the right gross pay you are looking for.

 

Test your current calculation implementation with inputs of 50 hours and $10 hourly rate. The correct result should be:

total = (40 * 10) + ((10) * (15));
total = $550
  • 0

You have a few issues in your code.  Look at your variable types too.

Convert.ToInt32

You're using this method to parse the numbers into doubles but you're using the method ToInt32 so you will lose anything anything the decimal point.    You want Convert.ToDouble().

total = (double) hours * (double) rate;

Not a bug but you don't need the (double) casts here.  You're doing double = double * double which is okay - no data loss.

  • 0

Keep it all doubles or floats internally. If you really need to cast it to integer do it as a one liner in the print statement.

That makes it easier to read and reduces rounding errors and excessive cpu cycles.

This should be a simple program. Look at your pseudo code and see if you can make it simpler?

  • 0

Now you need to split the homework grade with all of us ;)

 

I'll surely share my grade with the community. You guys rock!!  :D

 

 

man, i remember this exact problem on my business c# class final exam; crazy how many institutions reuse problems and examples for exams and homework

 

That's nuts, I guess they figure if its not broke, don't fix it. 

  • Like 2
  • 0

I'll surely share my grade with the community. You guys rock!!  :D

 

 

 

That's nuts, I guess they figure if its not broke, don't fix it. 

yea, i bet they share similar publishers/authors who have test bank questions, heck i just googled your problem and someone has a youtube video up on it as well, https://www.youtube.com/watch?v=qz7REN1qS6o, crazy

This topic is now closed to further replies.