<- Back to journalThis Week’s Programming Lesson: C# Lesson 3

This Week’s Programming Lesson: C# Lesson 3

Learn how to make C# actually use the information stored in variables by adding, subtracting, multiplying, dividing, and building a simple score calculator.

Tech / Development / Oct 6, 2026 / Roguegoose1

This Week’s Programming Lesson: C# Lesson 3

Making C# Do Some Math

Last week we started giving our program information.

We used Console.ReadLine() to ask the user questions, stored their answers in variables, and worked with a few basic types like string, int, float, and bool.

This week we are going to actually do something with some of that information.

Math.

Nothing crazy.

We are going to take numbers, add them together, subtract them, multiply them, divide them, and store the answers in new variables.

The goal is to start seeing variables as something we can actually use instead of just somewhere to store information.

Start With Two Numbers

Let's keep this simple.

Console.Write("Enter your first number: ");
int firstNumber = int.Parse(Console.ReadLine());

Console.Write("Enter your second number: ");
int secondNumber = int.Parse(Console.ReadLine());

int total = firstNumber + secondNumber;

Console.WriteLine("Your total is " + total);

If you enter:

10
5

The program prints:

Your total is 15

Nothing fancy.

But we just made the computer take two pieces of information from the user, do something with them, and give us a new answer.

Read It Like English

Just like last week, I want you to get used to reading the code in plain English.

This:

int total = firstNumber + secondNumber;

Can basically be read as:

"Add firstNumber and secondNumber, then store the answer in an integer called total."

That is it.

You do not need to make it more complicated than that.

Basic Math Operators

There are a handful of operators we are going to use all the time.

+
-
*
/
%

The first four should look pretty familiar.

+ adds.

- subtracts.

* multiplies.

/ divides.

Then we have %.

That one may look strange if you are new to programming.

It is called the modulus operator.

We will get to it in a minute.

Let's Use All Four

Start with this:

Console.Write("Enter your first number: ");
int firstNumber = int.Parse(Console.ReadLine());

Console.Write("Enter your second number: ");
int secondNumber = int.Parse(Console.ReadLine());

int added = firstNumber + secondNumber;
int subtracted = firstNumber - secondNumber;
int multiplied = firstNumber * secondNumber;
int divided = firstNumber / secondNumber;

Console.WriteLine("Added: " + added);
Console.WriteLine("Subtracted: " + subtracted);
Console.WriteLine("Multiplied: " + multiplied);
Console.WriteLine("Divided: " + divided);

Run it a few times with different numbers.

Try:

20
5

Then try:

7
2

You might notice something weird when you divide 7 by 2.

C# gives you:

3

Not:

3.5

Why?

Because we told C# these numbers were integers.

An int only stores whole numbers.

Bring Back Float

We learned about float last week.

Now it starts becoming a little more useful.

Try this:

Console.Write("Enter your first number: ");
float firstNumber = float.Parse(Console.ReadLine());

Console.Write("Enter your second number: ");
float secondNumber = float.Parse(Console.ReadLine());

float divided = firstNumber / secondNumber;

Console.WriteLine("Answer: " + divided);

Now enter:

7
2

And we can get:

3.5

This is one of the reasons data types matter.

The computer is doing exactly what you told it to do.

Sometimes the problem is that we told it the wrong thing.

You will experience that a lot in programming.

What the Heck Is %?

Now let's talk about this thing:

%

The modulus operator gives us the remainder after division.

For example:

int remainder = 10 % 3;

Three goes into ten three times, with one left over.

So:

remainder

will equal:

1

Try this:

Console.Write("Enter a number: ");
int number = int.Parse(Console.ReadLine());

int remainder = number % 2;

Console.WriteLine("Remainder: " + remainder);

If you enter an even number, the remainder will be 0.

If you enter an odd number, the remainder will be 1.

That is going to become useful very soon.

For now, just understand what it does.

Let's Make Something Slightly More Useful

Let's build a tiny score calculator.

Console.Write("What is your player name? ");
string playerName = Console.ReadLine();

Console.Write("How many enemies did you defeat? ");
int enemies = int.Parse(Console.ReadLine());

Console.Write("How many points is each enemy worth? ");
int pointsPerEnemy = int.Parse(Console.ReadLine());

int score = enemies * pointsPerEnemy;

Console.WriteLine(playerName + " earned " + score + " points.");

If Steve defeated 6 enemies and each enemy is worth 100 points:

Steve earned 600 points.

Now our variables are actually interacting with each other.

That is an important step.

Let's Add a Bonus

We can keep building on it.

Console.Write("What is your player name? ");
string playerName = Console.ReadLine();

Console.Write("How many enemies did you defeat? ");
int enemies = int.Parse(Console.ReadLine());

Console.Write("How many points is each enemy worth? ");
int pointsPerEnemy = int.Parse(Console.ReadLine());

Console.Write("How many bonus points did you earn? ");
int bonusPoints = int.Parse(Console.ReadLine());

int score = enemies * pointsPerEnemy;
int finalScore = score + bonusPoints;

Console.WriteLine(playerName + " earned " + finalScore + " points.");

Read this line:

int finalScore = score + bonusPoints;

As:

"Take the score, add the bonus points, and store the answer in finalScore."

Again, keep reading the code like English.

Let's Put Some of It Into Functions

We introduced functions in the first two lessons, so let's keep using them.

string playerName = GetPlayerName();
int enemies = GetEnemies();
int pointsPerEnemy = GetPointsPerEnemy();
int bonusPoints = GetBonusPoints();

int finalScore = CalculateScore(enemies, pointsPerEnemy, bonusPoints);

PrintScore(playerName, finalScore);

static string GetPlayerName()
{
    Console.Write("What is your player name? ");
    return Console.ReadLine();
}

static int GetEnemies()
{
    Console.Write("How many enemies did you defeat? ");
    return int.Parse(Console.ReadLine());
}

static int GetPointsPerEnemy()
{
    Console.Write("How many points is each enemy worth? ");
    return int.Parse(Console.ReadLine());
}

static int GetBonusPoints()
{
    Console.Write("How many bonus points did you earn? ");
    return int.Parse(Console.ReadLine());
}

static int CalculateScore(int enemies, int pointsPerEnemy, int bonusPoints)
{
    return (enemies * pointsPerEnemy) + bonusPoints;
}

static void PrintScore(string playerName, int finalScore)
{
    Console.WriteLine(playerName + " earned " + finalScore + " points.");
}

Do not get hung up on every little piece yet.

Look at this:

CalculateScore(enemies, pointsPerEnemy, bonusPoints);

We are sending three pieces of information into a function.

Then the function does this:

return (enemies * pointsPerEnemy) + bonusPoints;

It calculates an answer and sends that answer back.

That is really the important part.

Our Exercise for the Week

Same deal as before.

Type it.

Do not just stare at it.

Start with the tiny two-number calculator.

Then build the score calculator.

Then build the version using functions.

Change things.

Maybe enemies are worth 50 points.

Maybe add a penalty.

int finalScore = score + bonusPoints - penalty;

Maybe calculate the cost of five items.

Maybe calculate miles driven.

Maybe calculate hours worked times an hourly rate.

The point is not what you calculate.

The point is getting comfortable taking values stored in variables and doing something with them.

And yes, I still want repetition.

You probably do not need to type the whole giant version ten times every day.

But sit down every day this week and rebuild some version of it without copying and pasting.

That's It for This Week

Last week we learned how to get information into our program.

This week we learned how to actually use some of it.

Next week is where things get considerably more interesting.

Instead of the program doing the same thing every single time, we are going to let it start making decisions.

That means if, else if, and else.

And that is when our little programs start feeling a lot more like actual programs.