Code examples

Give change

Subtract the price from the amount paid to find the change.

Simple example

Start5 − 2
Result3
Program.cs
using System;

Console.WriteLine((5 - 2));
Output
3
Advertisements

Everyday examples

A customer pays 20 for a meal costing 13. How much change should they get?

Start20 − 13
Result7
Program.cs
using System;

int paid = 20;
int price = 13;
Console.WriteLine((paid - price));
Output
7
Run the example
Terminal
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
Official documentation