Array in C#: Monthly Expense Tracker
Table of Contents
- Array in C#: Monthly Expense Tracker
- Introduction of the Lesson
- Objectives
- Introductory Objective Statement
- Understand
- Learn
- Practice
- Apply
- Beginner-Friendly Source Code (With Namespace)
- Instructions
- Source Code
- Example Output
- Lesson Summary
- Multiple Choice Questions
- Exercises, Assessment, and Lab Exam
- Introduction to Exercises
- Exercises
- Assessment
- Lab Exam
Introduction of the Lesson
Arrays are essential in C# programming because they allow developers to store and manage multiple related values efficiently. In real-world applications, arrays are widely used in financial systems, budgeting tools, and expense tracking applications where handling multiple entries is necessary.
In this lesson, you will learn how to use arrays by building a Monthly Expense Tracker. This program simulates a real-life budgeting tool where daily or weekly expenses are recorded and processed to compute total and average spending. Managing expenses is a critical function in both personal finance and business operations, making this example highly relevant in practical scenarios.
By combining arrays with loops and basic arithmetic operations, you will understand how software systems help individuals and organizations monitor spending, control budgets, and make informed financial decisions.
Objectives
Introductory Objective Statement
The objectives of this lesson are designed to guide learners from foundational understanding to practical application. Through structured activities, students will gain the ability to use arrays in solving real-world financial problems.
Understand
Explain the concept of arrays and how they are used to store multiple expense values. Understand their importance in financial tracking systems.
Learn
Learn how to declare, initialize, and manipulate arrays in C#. Understand how loops are used to process expense data.
Practice
Practice writing programs that calculate total and average expenses using arrays. Strengthen skills in handling multiple inputs.
Apply
Apply knowledge to develop a simple budgeting tool that tracks monthly expenses and provides financial insights.
Beginner-Friendly Source Code (With Namespace)
Instructions
- Open Visual Studio Code.
- Create a new C# console application.
- Copy and paste the code below.
- Run the program.
- Observe how the program computes total and average expenses.
Source Code
using System;
namespace ExpenseTrackerApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== Monthly Expense Tracker ===");
// Array storing expenses for 7 days (example)
double[] expenses = { 1200, 850, 950, 1100, 780, 920, 1000 };
double totalExpense = 0;
// Loop to calculate total expenses
for (int i = 0; i < expenses.Length; i++)
{
totalExpense += expenses[i];
Console.WriteLine($"Day {i + 1} Expense: {expenses[i]}");
}
double averageExpense = totalExpense / expenses.Length;
Console.WriteLine("\n--- Summary ---");
Console.WriteLine($"Total Expense: {totalExpense}");
Console.WriteLine($"Average Daily Expense: {averageExpense}");
Console.ReadKey();
}
}
}
Example Output
=== Monthly Expense Tracker ===
Day 1 Expense: 1200
Day 2 Expense: 850
Day 3 Expense: 950
Day 4 Expense: 1100
Day 5 Expense: 780
Day 6 Expense: 920
Day 7 Expense: 1000
--- Summary ---
Total Expense: 6800
Average Daily Expense: 971.43
Lesson Summary
In this lesson, you learned how arrays can be used to manage and process multiple financial records efficiently. By building a Monthly Expense Tracker, you applied key programming concepts such as arrays, loops, and arithmetic operations to calculate total and average expenses. This demonstrates how programming can be used to solve real-world problems in budgeting and financial management. These skills are foundational for developing applications such as expense trackers, accounting systems, and financial dashboards.
Multiple Choice Questions
- What is an array used for in C#?
A. Storing one value
B. Storing multiple values
C. Printing output
D. Running loops - Why is a loop used in the expense tracker program?
A. To repeat input
B. To process each expense value
C. To stop the program
D. To create arrays - If total expense is 7000 and there are 7 days, what is the average?
A. 900
B. 1000
C. 1100
D. 1200 - What happens if one expense value is extremely high?
A. No effect
B. It increases the total and average
C. It deletes data
D. It stops execution - Why is an expense tracker important in business?
A. For entertainment
B. To monitor and control spending
C. To reduce coding
D. To increase errors
Exercises, Assessment, and Lab Exam
Introduction to Exercises
To enhance your programming and analytical skills, the following activities are designed to help you explore arrays in more depth. These exercises simulate real-world financial scenarios and encourage you to build more interactive and dynamic programs.
Exercises
- Modify the program to accept user input for daily expenses.
- Add functionality to identify the highest expense.
- Display the lowest expense recorded.
Assessment
- Create a program that tracks expenses for 30 days.
- Categorize expenses (e.g., food, transport, bills).
- Display total expenses per category.
Lab Exam
Task:
Develop a C# program that:
- Accepts 10 expense entries from the user
- Calculates total and average expenses
- Displays:
- Highest expense
- Lowest expense
- Total monthly expense
You may visit our Facebook page for more information, inquiries, and comments. Please subscribe also to our YouTube Channel to receive free capstone projects resources and computer programming tutorials.
Hire our team to do the project.