Im currently making a payroll system. I have like 5 or 6 employee's and each of them has a different hourly rate, how would I assign an hourly rate to each individual?!
At the moment I have something along the lines of(Which is incorrect)...
string[] employeeID = {"Brian", "Richard", etc....};
decimal hourlyPay = 0.0M;
if (employeeID == "Brian")
{
hourlyPay = 8.00M;
}
Thanks!
Try this code:
string[] employeeID = {"Brian", "Richard"};
decimal hourlyPay = 0.0M;
for (int i = 0; i < employeeID.Length; i++)
{
if (employeeID[i] == "Brian")
{
hourlyPay = 8.00M;
}
}
Console.WriteLine(hourlyPay);
Always use a loop to go through all elements in array, and access them by index. When populating, modifying elements, always use a loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With