Averaging the two salaries

Another common mathematical operation would be to find the average of the two salaries. Let's start by adding comment 10 as follows:

//10. totalSalary is a computed variable or calculated variable

What this means is that the value of totalSalary is the result of a calculation on the right side of the equals, so it's called a computed or calculated variable.

Next, we'll find an average. So, because totalSalary has already been created and its value has been set, we can use it in code that comes below that line:

decimal averageSalary = totalSalary / 2;

We start with decimal averageSalary =. To find an average of two quantities, you normally add them together and divide by two. However, it's a good idea to avoid using ...

Get Beginning C# 7 Hands-On – The Core Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.