private void Btn6_Click(object sender, EventArgs e) { if (HistoryTxtBox.Text.Contains('=')) { HistoryTxtBox.Clear(); ResultTxtBox.Clear(); } if (!(HistoryTxtBox.Text.LastOrDefault() == ')')) { ResultTxtBox.Text += "6"; } }
public bool FindResult() { try { if (HistoryTxtBox.Text.Contains('=')) { HistoryTxtBox.Clear(); } char sumbol = HistoryTxtBox.Text.Intersect(SumbolArr).LastOrDefault(); if (HistoryTxtBox.Text.Length == 0 || sumbol == '\0') { Result = Convert.ToDouble(ResultTxtBox.Text); } if (ResultTxtBox.Text.Length > 0) { if (sumbol == '+') { Result += Convert.ToDouble(ResultTxtBox.Text); } if (sumbol == '-') { Result -= Convert.ToDouble(ResultTxtBox.Text); } if (sumbol == '*') { if (Result == 0) { Result = 1; } Result *= Convert.ToDouble(ResultTxtBox.Text); } if (sumbol == '/') { if (Convert.ToDouble(ResultTxtBox.Text) == 0) { throw new Exception("Ошибка: Деления на нол!!!"); } Result /= Convert.ToDouble(ResultTxtBox.Text); } return(true); } } catch (Exception ex) { MessageBox.Show(ex.Message); ResultTxtBox.Clear(); } return(false); }
private void Btn0_Click(object sender, EventArgs e) { if (HistoryTxtBox.Text.Contains('=')) { HistoryTxtBox.Clear(); ResultTxtBox.Clear(); } if (!(HistoryTxtBox.Text.LastOrDefault() == ')')) { if ((!ResultTxtBox.Text.All(p => p == '0')) || (ResultTxtBox.Text.Length == 0)) { ResultTxtBox.Text += "0"; } } }
private void ProtsentBtn_Click(object sender, EventArgs e) { try { if (ResultTxtBox.Text.Length > 0 && HistoryTxtBox.Text.LastOrDefault() != ')') { if (HistoryTxtBox.Text.LastOrDefault() == '=') { HistoryTxtBox.Clear(); } HistoryTxtBox.Text += $"({ResultTxtBox.Text}%)"; ResultTxtBox.Text = (Result * Convert.ToDouble(ResultTxtBox.Text) / 100).ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); ResultTxtBox.Clear(); } }
private void CBtn_Click(object sender, EventArgs e) { ResultTxtBox.Clear(); HistoryTxtBox.Clear(); Result = 0; }