Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEEDED IN C# Create a C# console application to calculate gross pay. Workers in

ID: 3661896 • Letter: N

Question

NEEDED IN C#

Create a C# console application to calculate gross pay. Workers in a company work 40 hours per week. Any hours more than 40 will be considered as overtime work. The program should ask for three things: the number of hours the worker has worked this week, the pay rate for each regular hour of work and the pay rate for each overtime hour. The program should display three things: the base pay (i.e. the total pay for regular hours), the overtime pay (i.e. the total pay for overtime hours) and the gross pay (the total of base pay and overtime pay).

Explanation / Answer

Good Wishes,

First let me give you the required code, which is

A C# console application to calculate gross pay

using System.IO;
using System;

class Program
{
static void Main()
{
int worked_hrs=0,overtm_hrs=0;
float reg_pay=0.0f,ovtm_pay=0.0f,wbase_pay=0.0f,wovertm_pay=0.0f,wgross_pay=0.0f;
Console.WriteLine("Hello, Welcome! ");
Console.WriteLine("Please enter the number of hours the worker has worked for this week:");
worked_hrs = int.Parse(Console.ReadLine());
Console.WriteLine("Please enter the pay for each regular hour of work:");
reg_pay = float.Parse(Console.ReadLine());
Console.WriteLine("Please enter the pay for each overtime hour of work:");
ovtm_pay = float.Parse(Console.ReadLine());
if((worked_hrs < 40)||(worked_hrs==40))
{
overtm_hrs=0;
}
else if(worked_hrs >40)
{
overtm_hrs= worked_hrs - 40;
worked_hrs=40;
}
wbase_pay= worked_hrs * reg_pay;
wovertm_pay= overtm_hrs * ovtm_pay;
wgross_pay= wbase_pay + wovertm_pay;
Console.WriteLine("Base Pay: {0} Overtime Pay: {1} Gross Pay: {2}csharp ",wbase_pay,wovertm_pay,wgross_pay);
}
}

Explaination:

Intially I declared various variables which mean as below

worked_hrs- which is used to represent the number of hours the worker worked for in the week, this includes regular and overtime hours. It is initialized to zero.

overtm_hrs- which is used to represent the overtime hours the worker worked for in this week, it is intialized to zero

reg_pay- which is used to store the pay for a regular hour worked by a worker. It is initialized to 0.0

ovtm_pay- which is used to store the pay for an overtime hour the worker worked for. It is initialised to 0.0

wbase_pay- which is used to store the a workers base pay(i.e. the total pay for regular hours) for the week. It is intialised to 0.0

wovertm_pay-which is used to store the a workers overtime pay(i.e. the total pay for overtime hours) for the week. It is intialised to 0.0

wgross_pay-which is used to store the a workers gross pay (the total of base pay and overtime pay) for the week. It is intialised to 0.0

As input I asked for three things:

the number of hours the worker has worked this week,

the pay rate for each regular hour of work and

the pay rate for each overtime hour.

That is I asked the user to input values for worked_hrs, reg_pay and ovtm_pay.

Then I found out if the worked for any overtime hours by checking

if worked_hrs >40, if ture then

I assigned the extra hours to overtm_hrs, by doing

overtm_hrs= worked_hrs - 40

the remaining 40 hours which are considered as regular are placed in worked_hrs as below

worked_hrs=40

else if worked_hrs> 40 is false, which means either worked_hrs < 40 or worked_hrs =40, then

it shows that the worker didnot work for any overtime hours, hence

overtm_hrs=0.0

Then i calculated base pay, overtime pay and gross pay as below

wbase_pay= worked_hrs * reg_pay;
wovertm_pay= overtm_hrs * ovtm_pay;
wgross_pay= wbase_pay + wovertm_pay;

And finally I displayed three things:

the base pay (i.e. the total pay for regular hours),

the overtime pay (i.e. the total pay for overtime hours) and

the gross pay (the total of base pay and overtime pay).

Sample Output:

Hope this is clear. Please provide your valuable feedback(comments).