Answer:
The c# program for the scenario is shown.
using System;
class main {
static void Main() {
// arrays to hold details of employees are declared
// double datatype is taken to accommodate all types of numerical values
int[] empid = new int[3];
double[] hours = new double[3];
double[] pay = new double[3];
double[] pay_overtime = new double[3];
double hrs = 40.00;
double[] total_pay = new double[3];
Console.WriteLine("Enter the details for the three employees ");
// variable declared and initialized for the loop
int i=0;
while(i<3)
{
Console.WriteLine("Enter the id");
empid[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the working hours");
hours[i] = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter the hourly pay");
pay[i] = Double.Parse(Console.ReadLine());
pay_overtime[i] = pay[i]*1.5;
i++;
}
Console.WriteLine("The details for the three employees ");
// variable set to 0 to be re-used in the loop
i=0;
while(i<3)
{
if(hours[i] > hrs)
total_pay[i] = ( hrs*pay[i] );
else
total_pay[i] = ( hours[i]*pay[i] );
if(hours[i] > hrs)
total_pay[i] = total_pay[i] + ( (hours[i]-hrs)*pay_overtime[i] );
i++;
}
// variable set to 0 to be re-used in the loop
i=0;
while(i<3)
{
Console.WriteLine("Gross pay of employee " + (i+1) + " : " + total_pay[i] );
i++;
}
}
}
OUTPUT
Enter the details for the three employees
Enter the id
1
Enter the working hours
35
Enter the hourly pay
10
Enter the id
2
Enter the working hours
40
Enter the hourly pay
10
Enter the id
3
Enter the working hours
45
Enter the hourly pay
10
The details for the three employees
Gross pay of employee 1 : 350
Gross pay of employee 2 : 400
Gross pay of employee 3 : 475
Step-by-step explanation:
The program works as described.
1. Arrays to hold each piece of information for the employee, employee number, hourly pay, overtime pay and hours worked, are declared.
2. User input is taken inside while loop to fill each array for each employee.
3. The total gross pay for each employee is calculated inside another while loop.
4. The last while loop is used to display the gross pay for each employee.