diff options
| Commit | 657f9b35f4469f301cb458f423352edc53281743 (patch) | |
|---|---|---|
| Author | 2022-05-29 14:40:10 +0300 | |
| Committer | 2022-05-29 14:40:10 +0300 | |
| Files | 7cd49f3d84d2e54f587c908101772cd282e7b265 /src | |
| FMI-OOP-P2_Tables-657f9b35f4469f301cb458f423352edc53281743.tar FMI-OOP-P2_Tables-657f9b35f4469f301cb458f423352edc53281743.tar.gz FMI-OOP-P2_Tables-657f9b35f4469f301cb458f423352edc53281743.zip | ||
| Parent | e8f80d969c9280fbb13a9f8a62391e9f211f7786 (diff) | |
Autocommit at 29.05.2022 @ 14:40
2 files changed, 8 insertions, 4 deletions
| -rw-r--r-- | src/Models/CellFormula.cpp | 10 | ||||
| -rw-r--r-- | src/main.cpp | 2 |
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index 6aaeefd..942b6e5 100644 --- a/src/Models/CellFormula.cpp +++ b/src/Models/CellFormula.cpp @@ -71,7 +71,7 @@ void CellFormula::parseAndSetValue(const char* str) { } else { double val = atof(str); - while ((*str >= '0' && *str <= '9') || *str == ' ') str++; + while ((*str >= '0' && *str <= '9') || *str == ' ' || *str == '.') str++; currOp = *str; localCells.add(CellDouble(val)); @@ -80,8 +80,12 @@ void CellFormula::parseAndSetValue(const char* str) { if (currOp == '^') currOp *= -1; else if ((currOp == '+' || currOp == '-') && formula.get_count() != 0) { - Pair<Cell*, char>& prev = formula[formula.get_count() - 1]; - if (prev.right == '*' || prev.right == '/') prev.right *= -1; + unsigned cntr = 1; + Pair<Cell*, char>& prev = formula[formula.get_count() - cntr]; + while (prev.right == '*' || prev.right == '/') { + prev.right *= -1; + prev = formula[formula.get_count() - ++cntr]; + } } if (currOp == '-') { diff --git a/src/main.cpp b/src/main.cpp index ed0582f..640bc3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,7 @@ int main() { table.putCell(0, 0, "8.6"); table.putCell(0, 1, "3"); table.putCell(0, 2, "String"); - table.putCell(0, 3, "= 3 * R0C1 + R0C0 ^ R0C1 * 9 - 2 * 2 * 2 * 2 + 1"); + table.putCell(0, 3, "= 3 * R0C1 + R0C0 ^ R0C1 * 9 - 2 * 2.5 * 2 * 2 + 1"); // table.putCell(0, 3, "= 1 + 2 * 3 + 4 + 5"); UserInterface ui(&table); ui.run(); |
