CSharp Number Cruncher

Lessons → C# Book → Chapter 3
C# Book · Chapter 3

Project 1 — The Number Cruncher

Your first C# project is a console sandbox — a playful math engine that takes numbers in, transforms them, and spits out results instantly. No graphics yet. No UI. Just pure logic you can twist, bend, and break.

This is where C# starts feeling powerful: fast, structured, and surprisingly fun to manipulate.

Chapter 3 of 6

A playful math engine.

The Number Cruncher is a console program that:

  • asks the user for a number,
  • runs it through a series of transformations,
  • prints the results instantly,
  • and loops forever until you quit.

It’s simple — but the knobs you can twist are endless.


The prompt recipe.

Copy and paste this prompt into your AI assistant:

“Write a complete C# console application called The Number Cruncher. Include: 1. A loop that asks the user to enter a number. 2. A set of transformations: square the number, cube the number, take the square root, and multiply it by a random value. 3. Clear labels for each result. 4. A clean method structure: one method per transformation. 5. Comments explaining where to change the math to create new behaviors.”

Assemble the sandbox.

Once the AI gives you the code:

1
Create a new project

Open Visual Studio → Create a new project → Console App.

2
Paste the code

Replace everything in Program.cs with the AI’s output.

3
Run it

Press F5. Enter numbers. Watch the transformations happen instantly.

Now let’s twist the knobs.


Twisting the knobs (how to play).

These tweaks turn a simple console app into a surprisingly expressive sandbox.

🎲
Knob 1: Random multipliers
Find the method that multiplies the number by a random value:
double MultiplyRandom(double n)
{
  return n * Random.Shared.NextDouble();
}

The tweak: Multiply by a random number between 1 and 100 instead.

return n * Random.Shared.Next(1, 101);
📈
Knob 2: Add new transformations
Add a new method:
double Invert(double n)
{
  return 1.0 / n;
}

Then print it in the main loop. You just expanded the engine.

🌀
Knob 3: Chain reactions
Instead of transforming the original number each time, feed the output of one transformation into the next.

You’ve created a math synthesizer — one knob changes everything downstream.


What you just learned (naturally).

Without memorizing anything, you picked up:

  • Console I/O: Reading and writing text in a loop.
  • Method structure: Each transformation lives in its own method.
  • Types: C# requires you to specify int, double, string, etc.
  • Randomness: Using Random.Shared to generate unpredictable behavior.
  • Play‑First debugging: Change a number → run → observe → tweak.
You’re in C# Book · Chapter 3 of 6
Play‑First Programming · playfirstprogramming.com A clubhouse for curious builders