Skip to content

Commit

Permalink
fix bug: subtraction doesn't remove all leading zeros correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Last-Cookie committed Nov 29, 2020
1 parent c396e2a commit 2e67f9f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stringcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ std::string Decimal::sub(std::string minuend, std::string subtrahend) {
for (int i = 0; i < difference.length(); i++) {
if (difference[0] == '0') {
difference.erase(0, 1);

// In case difference contains several zeros
i--;
}
else {
break;
Expand Down Expand Up @@ -393,6 +396,8 @@ std::string Binary::sub_b(std::string minuend, std::string subtrahend) {
for (int i = 0; i < difference.length(); i++) {
if (difference[0] == '0') {
difference.erase(0, 1);

// In case difference contains several zeros
i--;
}
else {
Expand Down

0 comments on commit 2e67f9f

Please sign in to comment.