Small Project Organization
Helper Boundaries
A helper function gives one calculation a clear boundary and name.
Helper Boundaries
helper_boundaries.cpp
#include <iostream>
int applyDiscount(int price, int percent) {
return price - (price * percent / 100);
}
int main() {
int price = ;
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 = ;
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 = ;
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;
}
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.