Think about what an average is: it is the sum of all values, divided by teh number of values.
So if you have 4 values: 1, 2, 6, 7, then the average is (1 + 2 + 6 + 7) / 4, or 16 / 4 which is 4.
So you need to generate either generate a running total in your loop while the user is entering them, and divide after the loop, or add a second loop to generate the total once the entries are added.
I'd also suggest - pretty strongly - that you use
int.TryParse
instead of
int.Parse
. The latter throws an exception is the user enters anythgin that isn't a valid integer value, while the former returns a
true
/
false
value to indicate success / failure.
for (int i = 0; i < employees; i++)
{
int value = 0;
while (!int.TryParse(Console.ReadLine(), out value))
{
Console.Writeline("Please enter a valid integer only");
}
...
}
And we all know that everyone makes mistakes! It's pretty annoying to misskey while entering the 99th salary and have the program crash!