0
0
C Sharp (C#)programming~20 mins

Aggregate functions (Count, Sum, Average) in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Aggregate functions (Count, Sum, Average)
📖 Scenario: You work in a small store and want to analyze sales data to understand how many items were sold, the total sales amount, and the average price per item.
🎯 Goal: Build a simple C# program that uses aggregate functions to count items, sum prices, and calculate the average price from a list of sales.
📋 What You'll Learn
Create a list of sales with exact prices
Create a variable to hold the number of sales
Calculate the total sum of sales prices
Calculate the average price of sales
Print the count, sum, and average values
💡 Why This Matters
🌍 Real World
Stores and businesses often analyze sales data to understand performance and make decisions.
💼 Career
Knowing how to use aggregate functions like count, sum, and average is essential for data analysis and reporting in many programming jobs.
Progress0 / 4 steps
1
Create the sales data list
Create a List<double> called sales with these exact values: 10.5, 20.0, 15.75, 30.0, 25.25.
C Sharp (C#)
Need a hint?

Use List<double> and initialize it with the exact numbers inside curly braces.

2
Create a variable to count sales
Create an int variable called count and set it to the number of items in the sales list using sales.Count.
C Sharp (C#)
Need a hint?

Use int count = sales.Count; to get the number of items.

3
Calculate sum and average of sales
Create a double variable called sum and set it to the sum of all values in sales using sales.Sum(). Then create a double variable called average and set it to sum / count.
C Sharp (C#)
Need a hint?

Use sales.Sum() to get the total sum. Then divide by count to get the average.

4
Print the count, sum, and average
Write three Console.WriteLine statements to print the values of count, sum, and average exactly as shown:
Count: 5
Sum: 101.5
Average: 20.3.
Use average.ToString("F1") to format the average to one decimal place.
C Sharp (C#)
Need a hint?

Use Console.WriteLine with string interpolation and format average with ToString("F1").