Skip to content

Commit

Permalink
ean13 method added
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbacik committed Nov 5, 2023
1 parent f152795 commit e68c2ac
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/modules/commerce/Commerce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ std::string Commerce::productFullName()
{
return fmt::format("{} {} {}", productAdjective(), productMaterial(), productName());
}

std::string EAN13()
{
std::string barcode = String::numeric(12, false);

int sum = 0;
for (size_t i = 0; i < 12; i++)
{
sum += (i % 2 == 0) ? (barcode[i] - '0') : 3 * (barcode[i] - '0');
}
int checkDigit = (10 - (sum % 10)) % 10;

return barcode + std::to_string(checkDigit);
}
}

0 comments on commit e68c2ac

Please sign in to comment.