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);
}
}