Practice Projects
Vaibhav • September 11, 2025
You’ve now completed Chapter 2, which introduced data types and variables in C#. You’ve learned how to declare variables, work with numbers, strings, booleans, and dates, and even explored concepts like nullable types and memory management. To wrap up this chapter, let’s apply what you’ve learned in three beginner-friendly projects. These projects are designed to reinforce your understanding and give you a taste of how real programs are built - using only the concepts we’ve covered so far.
BMI Calculator
The Body Mass Index (BMI) is a simple health metric that uses a person’s height and weight to estimate body fat. The formula is:
BMI = weight / (height * height)
In this project, we’ll write a program that calculates BMI using variables. We’ll assume the height is in meters and weight is in kilograms.
double weight = 70.0;
double height = 1.75;
double bmi = weight / (height * height);
Console.WriteLine("Your BMI is:");
Console.WriteLine(bmi);
Let’s break this down:
We declare two double
variables: weight
and
height
. These are floating-point numbers because height and BMI often include
decimals. We then calculate bmi
using the formula and store the result in
another double
variable. Finally, we print the result.
You can change the values of weight
and height
to test different inputs. Later, when we learn about input and methods, we’ll make this program interactive.
Use double
for calculations that involve
decimals. This ensures your results are accurate and avoids rounding errors.
Age in Days Calculator
In this project, we’ll calculate a person’s age in days. This is a great way to practice working with DateTime
and TimeSpan
, which we introduced
earlier.
Let’s assume the person was born on January 1, 2000.
DateTime birthDate = new DateTime(2000, 1, 1);
DateTime today = DateTime.Now;
TimeSpan ageSpan = today - birthDate;
int ageInDays = ageSpan.Days;
Console.WriteLine("You are approximately this many days old:");
Console.WriteLine(ageInDays);
Here’s what’s happening:
We create a DateTime
variable called birthDate
and set it to January 1, 2000. We also get the current date and time using DateTime.Now
. Then we subtract birthDate
from
today
, which gives us a TimeSpan
- a duration.
We access the Days
part of that duration and store it in an int
variable called ageInDays
. Finally, we print
the result.
This project shows how you can use built-in types to do real-world calculations. You can change the birth date to test other cases.
DateTime
and TimeSpan
are powerful tools
for working with time. You can use them to
calculate durations, deadlines, and even countdowns.
Simple Enum-Based Menu System
In the last article, we learned about enum
- a way to define a set of named
constants. Let’s use that to build a simple menu system. This project won’t include user input yet, but it will
show how enums can organize your program.
enum MenuOption
{
Start,
Settings,
Exit
}
MenuOption selected = MenuOption.Settings;
Console.WriteLine("Selected option:");
Console.WriteLine(selected);
Here’s what we’re doing:
We define an enum called MenuOption
with three options: Start
, Settings
, and Exit
. Then we declare a variable called selected
and assign it one of the enum values. Finally, we print the selected option.
This kind of structure is useful when building menus, game states, or any system with fixed choices. You can
change the value of selected
to simulate different selections.
Enums help make your code more readable and less error-prone. Instead of using numbers or strings, you use named values that clearly describe what they mean.
Putting It All Together
These three projects show how the concepts from Chapter 2 come together in real programs. You’ve used:
int
,double
, andbool
for basic dataDateTime
andTimeSpan
for time calculationsenum
for organizing fixed choices- String interpolation to build messages
- Simple arithmetic and variable assignment
You didn’t need methods, classes, or control structures to build these programs. That’s because you’ve already learned enough to start writing useful code. As we move into the next chapter, we’ll introduce control flow - which will let you make decisions, repeat actions, and respond to user input.
Start small. Build simple programs that use the concepts you know. As you learn more, you can improve and expand them. Every big program starts with a small idea.
Summary
In this article, you built three beginner-friendly projects using only the concepts from Chapter 2. The BMI
calculator showed how to use double
and arithmetic. The age-in-days calculator
introduced DateTime
and TimeSpan
. The
enum-based menu system demonstrated how to organize fixed choices using enum
.
These projects reinforce everything you’ve learned so far and prepare you for the next step in your C# journey. You now understand how to work with data, perform calculations, and structure your code. In the next chapter, we’ll explore control flow - the logic that makes programs dynamic and responsive.