This commit is contained in:
EggMan20339 2024-02-01 12:00:04 -05:00
parent 08bc2c16e1
commit 50ec054dd0
2 changed files with 69 additions and 13 deletions

View File

@ -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;

View File

@ -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;
}
}
@ -170,7 +201,7 @@ namespace ElementaryMathematics
}
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();
}
}
}