A helper function gives one calculation a clear boundary and name.

helper Move repeated or named work into a helper when the name explains the rule.
boundary The caller supplies inputs, the helper returns a result, and the main flow stays readable.

Helper Boundaries

price
helper_boundaries.cpp
Replay: real traced execution (multi-file project)
#include <iostream>

int applyDiscount(int price, int percent) {
    return price - (price * percent / 100);
}

int main() {
    int price = 40;

    int discount = 25;
    int finalPrice = applyDiscount(price, discount);

    std::cout << "price=" << price << std::endl;
    std::cout << "discount=" << discount << std::endl;
    std::cout << "finalPrice=" << finalPrice << std::endl;
    return 0;
}
#include <iostream>

int applyDiscount(int price, int percent) {
    return price - (price * percent / 100);
}

int main() {
    int price = 15;

    int discount = 25;
    int finalPrice = applyDiscount(price, discount);

    std::cout << "price=" << price << std::endl;
    std::cout << "discount=" << discount << std::endl;
    std::cout << "finalPrice=" << finalPrice << std::endl;
    return 0;
}
#include <iostream>

int applyDiscount(int price, int percent) {
    return price - (price * percent / 100);
}

int main() {
    int price = 75;

    int discount = 25;
    int finalPrice = applyDiscount(price, discount);

    std::cout << "price=" << price << std::endl;
    std::cout << "discount=" << discount << std::endl;
    std::cout << "finalPrice=" << finalPrice << std::endl;
    return 0;
}
  1. price ← 40, discount ← 25

    7int main() {8    int price→ 40 = 40; //@price=15, 75910    int discount→ 25 = 25;11    int finalPrice = applyDiscount(price40, discount25);
  2. int applyDiscount(int price, int percent)

    3int applyDiscount(int price40, int percent25) {4    return price40 - (price * percent25 / 100);5}
  3. finalPrice ← 30

    10    int discount = 25;11    int finalPrice→ 30 = applyDiscount(price40, discount25);1213    std::cout << "price=" << price40 << std::endl;14    std::cout << "discount=" << discount25 << std::endl;15    std::cout << "finalPrice=" << finalPrice30 << std::endl;16    return 0;17}
    outputprice=40
    discount=25
    finalPrice=30
  1. price ← 15, discount ← 25

    7int main() {8    int price→ 15 = 15;910    int discount→ 25 = 25;11    int finalPrice = applyDiscount(price15, discount25);
  2. int applyDiscount(int price, int percent)

    3int applyDiscount(int price15, int percent25) {4    return price15 - (price * percent25 / 100);5}
  3. finalPrice ← 12

    10    int discount = 25;11    int finalPrice→ 12 = applyDiscount(price15, discount25);1213    std::cout << "price=" << price15 << std::endl;14    std::cout << "discount=" << discount25 << std::endl;15    std::cout << "finalPrice=" << finalPrice12 << std::endl;16    return 0;17}
    outputprice=15
    discount=25
    finalPrice=12
  1. price ← 75, discount ← 25

    7int main() {8    int price→ 75 = 75;910    int discount→ 25 = 25;11    int finalPrice = applyDiscount(price75, discount25);
  2. int applyDiscount(int price, int percent)

    3int applyDiscount(int price75, int percent25) {4    return price75 - (price * percent25 / 100);5}
  3. finalPrice ← 57

    10    int discount = 25;11    int finalPrice→ 57 = applyDiscount(price75, discount25);1213    std::cout << "price=" << price75 << std::endl;14    std::cout << "discount=" << discount25 << std::endl;15    std::cout << "finalPrice=" << finalPrice57 << std::endl;16    return 0;17}
    outputprice=75
    discount=25
    finalPrice=57