O'Reilly logo

Beginning C# 7 Hands-On – The Core Language by Tom Owsiak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required