Skip to content

Commit

Permalink
Fixed "empty field" error
Browse files Browse the repository at this point in the history
Application was crashing if user clicked "Calculate" while drawing field was empty. Added necessary additional if-statements.
  • Loading branch information
kamil-matula committed Jun 17, 2021
1 parent 23725fd commit e88336a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions Digit Recognizer - Main App/Calculation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Calculation // To calculate RPN: string result = toRPN(dzialanie); Stack<s
{
public static string Calculate(string equation)
{
if (equation.Length == 0) return "DRAWING FIELD IS EMPTY!";
if (equation.EndsWith(" - ") || equation.EndsWith(" + ") || equation.EndsWith(" * ") || equation.EndsWith(" / ") || equation.Contains(" "))
return "INCORRECT EXPRESSION!";
if (equation.StartsWith(" - ") || equation.StartsWith(" + ") || equation.StartsWith(" * ") || equation.StartsWith(" / "))
Expand Down
2 changes: 1 addition & 1 deletion Digit Recognizer - Main App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void CalculateButtonClick(object sender, RoutedEventArgs e)
string tmp = DigitDetection.RecognizeDigits(digits, network);
if (tmp != "") MathTextBox.Text = tmp;
string result = Calculation.Calculate(tmp).ToString();
if (result == "INCORRECT EXPRESSION!" || result == "YOU CAN'T DIVIDE BY ZERO!") MathTextBox.Text = result;
if (result == "INCORRECT EXPRESSION!" || result == "YOU CAN'T DIVIDE BY ZERO!" || result == "DRAWING FIELD IS EMPTY!") MathTextBox.Text = result;
else MathTextBox.Text += result;
}
#endregion
Expand Down
Binary file modified Digit Recognizer - Main App/bin/Debug/DigitRecognizer.exe
Binary file not shown.
Binary file modified Digit Recognizer - Main App/bin/Debug/DigitRecognizer.pdb
Binary file not shown.

0 comments on commit e88336a

Please sign in to comment.