From 50ec054dd006c88b5f415cf46197e8cbeb6b7be3 Mon Sep 17 00:00:00 2001 From: EggMan20339 <99349302+EggMan20339@users.noreply.github.com> Date: Thu, 1 Feb 2024 12:00:04 -0500 Subject: [PATCH] finished --- ElementaryMathematics/Form1.Designer.cs | 19 ++++++-- ElementaryMathematics/Form1.cs | 63 +++++++++++++++++++++---- 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/ElementaryMathematics/Form1.Designer.cs b/ElementaryMathematics/Form1.Designer.cs index 40dfd09..13a066a 100644 --- a/ElementaryMathematics/Form1.Designer.cs +++ b/ElementaryMathematics/Form1.Designer.cs @@ -41,6 +41,7 @@ this.lblDisIncorrect = new System.Windows.Forms.Label(); this.lblDisCorrect = new System.Windows.Forms.Label(); this.pnlCalc = new System.Windows.Forms.Panel(); + this.lblDisInfo = new System.Windows.Forms.Label(); this.lblImage = new System.Windows.Forms.Label(); this.btnReset = new System.Windows.Forms.Button(); this.btnClear = new System.Windows.Forms.Button(); @@ -160,6 +161,7 @@ // // pnlCalc // + this.pnlCalc.Controls.Add(this.lblDisInfo); this.pnlCalc.Controls.Add(this.lblImage); this.pnlCalc.Controls.Add(this.btnReset); this.pnlCalc.Controls.Add(this.btnClear); @@ -176,6 +178,15 @@ this.pnlCalc.Size = new System.Drawing.Size(698, 155); this.pnlCalc.TabIndex = 3; // + // lblDisInfo + // + this.lblDisInfo.Location = new System.Drawing.Point(367, 15); + this.lblDisInfo.Name = "lblDisInfo"; + this.lblDisInfo.Size = new System.Drawing.Size(106, 29); + this.lblDisInfo.TabIndex = 11; + this.lblDisInfo.Text = "Rount to the Nearest Hundredth (x.xx)"; + this.lblDisInfo.Click += new System.EventHandler(this.label1_Click); + // // lblImage // this.lblImage.Location = new System.Drawing.Point(508, 37); @@ -225,9 +236,9 @@ // // lblMessage // - this.lblMessage.Location = new System.Drawing.Point(425, 101); + this.lblMessage.Location = new System.Drawing.Point(380, 101); this.lblMessage.Name = "lblMessage"; - this.lblMessage.Size = new System.Drawing.Size(77, 24); + this.lblMessage.Size = new System.Drawing.Size(206, 24); this.lblMessage.TabIndex = 5; // // lblOperator @@ -300,7 +311,7 @@ this.btnPrint.Name = "btnPrint"; this.btnPrint.Size = new System.Drawing.Size(106, 34); this.btnPrint.TabIndex = 6; - this.btnPrint.Text = "Print"; + this.btnPrint.Text = "Print Summary"; this.btnPrint.UseVisualStyleBackColor = true; this.btnPrint.Click += new System.EventHandler(this.button1_Click); // @@ -329,6 +340,8 @@ this.ResumeLayout(false); } + private System.Windows.Forms.Label lblDisInfo; + private System.Windows.Forms.Button btnExit; private System.Windows.Forms.Button btnPrint; diff --git a/ElementaryMathematics/Form1.cs b/ElementaryMathematics/Form1.cs index e66bcc6..8adb4ee 100644 --- a/ElementaryMathematics/Form1.cs +++ b/ElementaryMathematics/Form1.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Diagnostics.Eventing.Reader; using System.Drawing; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,6 +24,7 @@ namespace ElementaryMathematics private Int32 numRunningIncorrect = 0; private bool hasTried = false; + private bool isError = false; public Form1() @@ -61,7 +63,13 @@ namespace ElementaryMathematics private void button1_Click(object sender, EventArgs e) { - // throw new System.NotImplementedException(); + decimal total = (numRunningCorrect - numRunningIncorrect) * 100; + + MessageBox.Show("Your Score:" + + "\nCorrect: " + numRunningCorrect + + "\nIncorrect: " + numRunningIncorrect + + "\nTotal Score : " + (total.ToString()+"!")); + } private void ChangeOperator(string op) @@ -100,21 +108,33 @@ namespace ElementaryMathematics private void rdoAddition_CheckedChanged(object sender, EventArgs e) { ChangeOperator("+"); + UpdateButtons(); + isError = false; + hasTried = false; } private void rdoSubtraction_CheckedChanged(object sender, EventArgs e) { ChangeOperator("-"); + UpdateButtons(); + isError = false; + hasTried = false; } private void rdoMultiplication_CheckedChanged(object sender, EventArgs e) { ChangeOperator("*"); + UpdateButtons(); + isError = false; + hasTried = false; } private void rdoDivision_CheckedChanged(object sender, EventArgs e) { ChangeOperator("/"); + UpdateButtons(); + isError = false; + hasTried = false; } private void btnExit_Click(object sender, EventArgs e) @@ -137,24 +157,35 @@ namespace ElementaryMathematics { answer = a + b; hasTried = true; + return answer; }else if (isSubtract) { answer = a - b; hasTried = true; + return answer; }else if (isMultiply) { answer = a * b; hasTried = true; + return answer; }else if (isDivide) { hasTried = true; if (b != 0) { - answer = a / b; + string newan; + answer = a / b; + newan = answer.ToString("F"); + answer = decimal.Parse(newan); + return answer; } else { - throw new Exception(); + ep1.SetError(btnChkAnswer, "Cannot Divide by 0!"); + isError = true; + answer = new decimal(null); + return answer; + } } @@ -168,9 +199,9 @@ namespace ElementaryMathematics { ep1.SetError(btnChkAnswer, "Calculation Error"); } - - return answer; + + return new decimal(null); } private void Win() @@ -231,7 +262,7 @@ namespace ElementaryMathematics } catch (Exception exception) { - ep1.SetError(btnChkAnswer, "Calculation Error"); + MessageBox.Show("NaN", "Error", MessageBoxButtons.OK); } @@ -265,21 +296,21 @@ namespace ElementaryMathematics private void txtA_TextChanged(object sender, EventArgs e) { - ep1.Clear(); + isError = false; hasTried = false; UpdateButtons(); } private void txtB_TextChanged(object sender, EventArgs e) { - ep1.Clear(); + isError = false; hasTried = false; UpdateButtons(); } private void txtC_TextChanged(object sender, EventArgs e) { - ep1.Clear(); + isError = false; hasTried = false; UpdateButtons(); lblMessage.Text = ""; @@ -346,11 +377,18 @@ namespace ElementaryMathematics { btnReset.Enabled = true; + btnPrint.Enabled = true; } else { btnReset.Enabled = false; + btnPrint.Enabled = false; + } + + if (!isError) + { + ep1.Clear(); } } @@ -379,7 +417,7 @@ namespace ElementaryMathematics try { - lblMessage.Text = Calculate(a, b).ToString(); + lblMessage.Text = "Correct Answer: " + Calculate(a, b).ToString("F"); } catch (Exception exception) @@ -407,5 +445,10 @@ namespace ElementaryMathematics UpdateButtons(); } + + private void label1_Click(object sender, EventArgs e) + { + // throw new System.NotImplementedException(); + } } } \ No newline at end of file