Skip to the lesson

CodingLesson 5 of 6

Part 1 of 3, 0 done

13 min

Functions: one rule for the whole crew

The food truck's crew makes change at three different tills. Write the rule once, give it a name, and every till uses the same one.

Ticket 01 · Your turn

What does the till get back?

Every till on the truck uses this procedure. paid and cost are its parameters; RETURN sends the answer back to whoever called it.

PROCEDURE change(paid, cost)
{
   RETURN(paid - cost)
}

A worked call:

change(10, 6.50)

runs with paid as $10.00example (example number: Simplified example: the worked call's cash.) and cost as $6.50example (example number: Simplified example.), and sends back $3.50example (example number: Worked out: the worked call's cash minus its cost.).

Now a customer pays $20.00example (example number: Simplified example: cash handed over.) for a $7.25example (example number: Simplified example: the order's cost.) order. What does this call send back?

due ← change(20, 7.25)

What you know

Paid
$20.00
Cost of the order
$7.25

These numbers are our example.

$
Words to know

Spot something wrong?

Tell us what looks off. No name or email needed.

What kind of problem?

0 / 1000

We'll also send this page, the lesson, ticket 1, so we can find it. Nothing else. Privacy

·
Sources and every number

Every number

  • $10.00example (example number: Simplified example: the worked call's cash.) · Simplified example: the worked call's cash.
  • $6.50example (example number: Simplified example.) · Simplified example.
  • $3.50example (example number: Worked out: the worked call's cash minus its cost.) · Worked out: the worked call's cash minus its cost.
  • $20.00example (example number: Simplified example: cash handed over.) · Simplified example: cash handed over.
  • $7.25example (example number: Simplified example: the order's cost.) · Simplified example: the order's cost.
  • $12.75example (example number: Worked out: the cash handed over minus the order's cost.) · Worked out: the cash handed over minus the order's cost.
  1. Lessons›
  2. The school›
  3. Coding
  • ·Before this: Loops: working through the order queue
  • ·Next: Debugging: find the bug like a detective
Skip to the lesson

CodingLesson 5 of 6

Part 1 of 3, 0 done

13 min

Functions: one rule for the whole crew

The food truck's crew makes change at three different tills. Write the rule once, give it a name, and every till uses the same one.

Ticket 01 · Your turn

What does the till get back?

Every till on the truck uses this procedure. paid and cost are its parameters; RETURN sends the answer back to whoever called it.

PROCEDURE change(paid, cost)
{
   RETURN(paid - cost)
}

A worked call:

change(10, 6.50)

runs with paid as $10.00example (example number: Simplified example: the worked call's cash.) and cost as $6.50example (example number: Simplified example.), and sends back $3.50example (example number: Worked out: the worked call's cash minus its cost.).

Now a customer pays $20.00example (example number: Simplified example: cash handed over.) for a $7.25example (example number: Simplified example: the order's cost.) order. What does this call send back?

due ← change(20, 7.25)

What you know

Paid
$20.00
Cost of the order
$7.25

These numbers are our example.

$
Words to know

Spot something wrong?

Tell us what looks off. No name or email needed.

What kind of problem?

0 / 1000

We'll also send this page, the lesson, ticket 1, so we can find it. Nothing else. Privacy

·
Sources and every number

Every number

  • $10.00example (example number: Simplified example: the worked call's cash.) · Simplified example: the worked call's cash.
  • $6.50example (example number: Simplified example.) · Simplified example.
  • $3.50example (example number: Worked out: the worked call's cash minus its cost.) · Worked out: the worked call's cash minus its cost.
  • $20.00example (example number: Simplified example: cash handed over.) · Simplified example: cash handed over.
  • $7.25example (example number: Simplified example: the order's cost.) · Simplified example: the order's cost.
  • $12.75example (example number: Worked out: the cash handed over minus the order's cost.) · Worked out: the cash handed over minus the order's cost.
  1. Lessons›
  2. The school›
  3. Coding
  • ·Before this: Loops: working through the order queue
  • ·Next: Debugging: find the bug like a detective