C# Foundations · Lesson 17

A small bill

Add a few decimal amounts and print the total.

How it works

spent holds 12.50, 4.25, and 8. Sum walks all three. 12.50 + 4.25 is 16.75, and 16.75 + 8 is 24.75. Write the values before you add them. The m on each literal keeps the total in decimal.

A working example

using System.Linq;

var spent = new[] { 12.50m, 4.25m, 8m };
var total = spent.Sum();
Console.WriteLine(total);

Expected output

24.75
Try this
Write the values before you add them.