0% found this document useful (0 votes)
21 views2 pages

2D Array - Examples

The document outlines a program for tracking employee salaries using a 2D array. It allows the user to input up to 10 employee names and salaries, then displays the full list, calculates the average salary, and identifies the employee with the highest salary. The program is implemented in C# and includes error handling for exceeding the maximum number of employees.

Uploaded by

vdwaltleeann
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

2D Array - Examples

The document outlines a program for tracking employee salaries using a 2D array. It allows the user to input up to 10 employee names and salaries, then displays the full list, calculates the average salary, and identifies the employee with the highest salary. The program is implemented in C# and includes error handling for exceeding the maximum number of employees.

Uploaded by

vdwaltleeann
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Scenario: Employee Salary Tracker

Your company needs a simple system to keep track of employee


salaries. Write a program that:
1. Asks the user how many employees they want to enter
(maximum of 10).
2. Uses a 2D array to store:
 Column 0 → Employee names
 Column 1 → Salaries
3. Prompts the user to input each employee’s name and salary.
4. After all data is entered, the program should:
 Display the full list of employees with their salaries.
 Calculate and display the average salary.
 Find and display the employee with the highest salary.
Solution:
using System;

public class Program


{
public static void Main()
{
int MaxEmployees = 10;
string [,] Employees = new string[MaxEmployees,2];
[Link]("Please enter the number of emplyees: (Max 10)");
int numEmp = [Link]([Link]());

if(numEmp > MaxEmployees)


{
[Link]("Too many employees!");
numEmp = MaxEmployees;
}

for(int i = 0; i < numEmp; i++)


{
[Link]("Please enter the employee details: ");

[Link]("Name: ");
Employees[i , 0] = [Link]();
[Link]("Salary: ");
Employees[i , 1] = [Link]();
}
[Link]("Employee List: ");
decimal totalSalary = 0;
decimal highestSalary = 0;
string highestPaid = "";

for(int i = 0; i < numEmp; i++)


{
string name = Employees[i,0];
decimal salary = [Link](Employees[i, 1]);

[Link]("{0}: {1}", name, salary);


totalSalary += salary;

if(salary > highestSalary)


{
highestSalary = salary;
highestPaid = name;
}
}
decimal AgvSal = totalSalary/numEmp;
[Link]("Average Salary is: {0}", AgvSal);
[Link]("Highest paid: {0}", highestPaid);
}
}

You might also like