2024-02-01 09:26:21 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
2024-02-01 10:08:18 -05:00
|
|
|
|
using System.Diagnostics.Eventing.Reader;
|
2024-02-01 09:26:21 -05:00
|
|
|
|
using System.Drawing;
|
2024-02-01 12:00:04 -05:00
|
|
|
|
using System.Globalization;
|
2024-02-01 09:26:21 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ElementaryMathematics
|
|
|
|
|
{
|
|
|
|
|
public partial class Form1 : Form
|
|
|
|
|
{
|
2024-02-01 10:08:18 -05:00
|
|
|
|
|
|
|
|
|
private bool isAdd = false;
|
|
|
|
|
private bool isSubtract = false;
|
|
|
|
|
private bool isMultiply = false;
|
|
|
|
|
private bool isDivide = false;
|
2024-02-01 10:28:46 -05:00
|
|
|
|
|
|
|
|
|
private Int32 numRunningCorrect = 0;
|
|
|
|
|
private Int32 numRunningIncorrect = 0;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
|
|
|
|
private bool hasTried = false;
|
2024-02-01 12:00:04 -05:00
|
|
|
|
private bool isError = false;
|
2024-02-01 10:28:46 -05:00
|
|
|
|
|
2024-02-01 10:08:18 -05:00
|
|
|
|
|
2024-02-01 09:26:21 -05:00
|
|
|
|
public Form1()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
|
|
|
|
pnlSummary.Visible = false;
|
|
|
|
|
lblNumCorrect.Text = "0";
|
|
|
|
|
lblNumIncorrect.Text = "0";
|
|
|
|
|
UpdateButtons();
|
2024-02-01 09:26:21 -05:00
|
|
|
|
}
|
2024-02-01 09:56:22 -05:00
|
|
|
|
|
|
|
|
|
private void groupBox1_Enter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// throw new System.NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void radioButton1_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// throw new System.NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 10:54:15 -05:00
|
|
|
|
private void chkSummary_CheckedChanged(object sender, EventArgs e)
|
2024-02-01 09:56:22 -05:00
|
|
|
|
{
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
|
|
|
|
if (chkShowSummary.Checked)
|
|
|
|
|
{
|
|
|
|
|
pnlSummary.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pnlSummary.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 09:56:22 -05:00
|
|
|
|
}
|
2024-02-01 09:57:29 -05:00
|
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-01 12:00:04 -05:00
|
|
|
|
decimal total = (numRunningCorrect - numRunningIncorrect) * 100;
|
|
|
|
|
|
|
|
|
|
MessageBox.Show("Your Score:" +
|
|
|
|
|
"\nCorrect: " + numRunningCorrect +
|
|
|
|
|
"\nIncorrect: " + numRunningIncorrect +
|
|
|
|
|
"\nTotal Score : " + (total.ToString()+"!"));
|
|
|
|
|
|
2024-02-01 09:57:29 -05:00
|
|
|
|
}
|
2024-02-01 10:08:18 -05:00
|
|
|
|
|
|
|
|
|
private void ChangeOperator(string op)
|
|
|
|
|
{
|
|
|
|
|
isAdd = false;
|
|
|
|
|
isSubtract = false;
|
|
|
|
|
isMultiply = false;
|
|
|
|
|
isDivide = false;
|
|
|
|
|
|
|
|
|
|
if (op == "+")
|
|
|
|
|
{
|
|
|
|
|
isAdd = true;
|
|
|
|
|
lblOperator.Text = op;
|
|
|
|
|
}else if (op == "-")
|
|
|
|
|
{
|
|
|
|
|
isSubtract = true;
|
|
|
|
|
lblOperator.Text = op;
|
|
|
|
|
}else if (op == "*")
|
|
|
|
|
{
|
|
|
|
|
isMultiply = true;
|
|
|
|
|
lblOperator.Text = op;
|
|
|
|
|
}else if (op == "/")
|
|
|
|
|
{
|
|
|
|
|
isDivide = true;
|
|
|
|
|
lblOperator.Text = op;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lblOperator.Text = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void rdoAddition_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ChangeOperator("+");
|
2024-02-01 12:00:04 -05:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
isError = false;
|
|
|
|
|
hasTried = false;
|
2024-02-01 10:08:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void rdoSubtraction_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ChangeOperator("-");
|
2024-02-01 12:00:04 -05:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
isError = false;
|
|
|
|
|
hasTried = false;
|
2024-02-01 10:08:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void rdoMultiplication_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ChangeOperator("*");
|
2024-02-01 12:00:04 -05:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
isError = false;
|
|
|
|
|
hasTried = false;
|
2024-02-01 10:08:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void rdoDivision_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ChangeOperator("/");
|
2024-02-01 12:00:04 -05:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
isError = false;
|
|
|
|
|
hasTried = false;
|
2024-02-01 10:08:18 -05:00
|
|
|
|
}
|
2024-02-01 10:10:31 -05:00
|
|
|
|
|
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2024-02-01 10:28:46 -05:00
|
|
|
|
|
|
|
|
|
private ErrorProvider ep1 = new ErrorProvider();
|
|
|
|
|
|
2024-02-01 11:03:13 -05:00
|
|
|
|
private decimal Calculate(decimal a, decimal b)
|
2024-02-01 10:28:46 -05:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
decimal answer = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (isAdd)
|
|
|
|
|
{
|
|
|
|
|
answer = a + b;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
hasTried = true;
|
2024-02-01 12:00:04 -05:00
|
|
|
|
return answer;
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}else if (isSubtract)
|
|
|
|
|
{
|
|
|
|
|
answer = a - b;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
hasTried = true;
|
2024-02-01 12:00:04 -05:00
|
|
|
|
return answer;
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}else if (isMultiply)
|
|
|
|
|
{
|
|
|
|
|
answer = a * b;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
hasTried = true;
|
2024-02-01 12:00:04 -05:00
|
|
|
|
return answer;
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}else if (isDivide)
|
|
|
|
|
{
|
2024-02-01 10:54:15 -05:00
|
|
|
|
hasTried = true;
|
2024-02-01 11:03:13 -05:00
|
|
|
|
if (b != 0)
|
|
|
|
|
{
|
2024-02-01 12:00:04 -05:00
|
|
|
|
string newan;
|
|
|
|
|
answer = a / b;
|
|
|
|
|
newan = answer.ToString("F");
|
|
|
|
|
answer = decimal.Parse(newan);
|
|
|
|
|
return answer;
|
2024-02-01 11:03:13 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-01 12:00:04 -05:00
|
|
|
|
ep1.SetError(btnChkAnswer, "Cannot Divide by 0!");
|
|
|
|
|
isError = true;
|
|
|
|
|
answer = new decimal(null);
|
|
|
|
|
return answer;
|
|
|
|
|
|
2024-02-01 11:03:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2024-02-01 11:03:13 -05:00
|
|
|
|
ep1.SetError(btnChkAnswer, "Calculation Error");
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 12:00:04 -05:00
|
|
|
|
|
|
|
|
|
return new decimal(null);
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Win()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
lblMessage.Text = "Good Job!";
|
|
|
|
|
numRunningCorrect++;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
lblNumCorrect.Text = numRunningCorrect.ToString();
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Fail()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
lblMessage.Text = "Try Again";
|
|
|
|
|
numRunningIncorrect++;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
lblNumIncorrect.Text = numRunningIncorrect.ToString();
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void btnChkAnswer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ep1.Clear();
|
|
|
|
|
|
|
|
|
|
decimal a = 0;
|
|
|
|
|
decimal b = 0;
|
|
|
|
|
decimal c = 0;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
a = decimal.Parse(txtA.Text);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
b = decimal.Parse(txtB.Text);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
c = decimal.Parse(txtC.Text);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
2024-02-01 11:03:13 -05:00
|
|
|
|
if (c == Calculate(a,b))
|
2024-02-01 10:28:46 -05:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Win();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
2024-02-01 12:00:04 -05:00
|
|
|
|
MessageBox.Show("NaN", "Error", MessageBoxButtons.OK);
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ep1.SetError(txtC, "Invalid Value");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ep1.SetError(txtB, "Invalid Value");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ep1.SetError(txtA, "Invalid Value");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 10:54:15 -05:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtA_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-01 12:00:04 -05:00
|
|
|
|
isError = false;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
hasTried = false;
|
|
|
|
|
UpdateButtons();
|
2024-02-02 08:03:31 -05:00
|
|
|
|
ep1.Clear();
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtB_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-01 12:00:04 -05:00
|
|
|
|
isError = false;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
hasTried = false;
|
|
|
|
|
UpdateButtons();
|
2024-02-02 08:03:31 -05:00
|
|
|
|
ep1.Clear();
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtC_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-01 12:00:04 -05:00
|
|
|
|
isError = false;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
hasTried = false;
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
lblMessage.Text = "";
|
2024-02-02 08:03:31 -05:00
|
|
|
|
ep1.Clear();
|
2024-02-01 10:54:15 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnClear_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
txtA.Clear();
|
|
|
|
|
txtB.Clear();
|
|
|
|
|
txtC.Clear();
|
|
|
|
|
|
|
|
|
|
UpdateButtons();
|
2024-02-02 08:03:31 -05:00
|
|
|
|
ep1.Clear();
|
2024-02-01 10:54:15 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnReset_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-02-01 20:19:13 -05:00
|
|
|
|
|
|
|
|
|
DialogResult btnDialog;
|
|
|
|
|
string strResponse;
|
|
|
|
|
|
|
|
|
|
strResponse = "Do you really want to reset all statistics?";
|
|
|
|
|
|
|
|
|
|
btnDialog = MessageBox.Show(strResponse, "Chapter Four", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
|
|
|
|
|
|
|
|
|
|
if (btnDialog == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
btnClear_Click(sender, e);
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
2024-02-01 20:19:13 -05:00
|
|
|
|
numRunningCorrect = 0;
|
|
|
|
|
numRunningIncorrect = 0;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
2024-02-01 20:19:13 -05:00
|
|
|
|
UpdateButtons();
|
|
|
|
|
rdoAddition.Select();
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
2024-02-01 20:19:13 -05:00
|
|
|
|
lblNumCorrect.Text = "0";
|
|
|
|
|
lblNumIncorrect.Text = "0";
|
2024-02-01 21:05:10 -05:00
|
|
|
|
|
|
|
|
|
txtA.Focus();
|
2024-02-01 20:19:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 10:54:15 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateButtons()
|
|
|
|
|
{
|
|
|
|
|
|
2024-02-01 11:03:13 -05:00
|
|
|
|
if (txtA.TextLength > 0 && txtB.TextLength > 0 && txtC.TextLength > 0 && !hasTried)
|
2024-02-01 10:54:15 -05:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
btnChkAnswer.Enabled = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
btnChkAnswer.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasTried)
|
|
|
|
|
{
|
|
|
|
|
btnShowCorrectAnswer.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
btnShowCorrectAnswer.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (txtA.TextLength > 0 || txtB.TextLength > 0 || txtC.TextLength > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
btnClear.Enabled = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
btnClear.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (numRunningCorrect > 0 || numRunningIncorrect > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
btnReset.Enabled = true;
|
2024-02-01 12:00:04 -05:00
|
|
|
|
btnPrint.Enabled = true;
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
btnReset.Enabled = false;
|
2024-02-01 12:00:04 -05:00
|
|
|
|
btnPrint.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-02 08:03:31 -05:00
|
|
|
|
// if (!isError)
|
|
|
|
|
// {
|
|
|
|
|
// ep1.Clear();
|
|
|
|
|
// }
|
2024-02-01 10:54:15 -05:00
|
|
|
|
|
2024-02-01 10:28:46 -05:00
|
|
|
|
}
|
2024-02-01 11:03:13 -05:00
|
|
|
|
|
|
|
|
|
private void btnShowCorrectAnswer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ep1.Clear();
|
|
|
|
|
|
|
|
|
|
decimal a = 0;
|
|
|
|
|
decimal b = 0;
|
|
|
|
|
decimal c = 0;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
a = decimal.Parse(txtA.Text);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
b = decimal.Parse(txtB.Text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
2024-02-01 12:00:04 -05:00
|
|
|
|
lblMessage.Text = "Correct Answer: " + Calculate(a, b).ToString("F");
|
2024-02-01 11:03:13 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
ep1.SetError(btnChkAnswer, "Calculation Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ep1.SetError(txtB, "Invalid Value");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ep1.SetError(txtA, "Invalid Value");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
|
|
|
|
|
}
|
2024-02-01 12:00:04 -05:00
|
|
|
|
|
|
|
|
|
private void label1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// throw new System.NotImplementedException();
|
|
|
|
|
}
|
2024-02-01 09:26:21 -05:00
|
|
|
|
}
|
|
|
|
|
}
|