Microsoft
Software
Hardware
Network
Question : Help Please!
This is the question:
develop a basic calculator that operates on real numbers. The Graphical User Interface
I HAVE DONE ALL THE WORK AND MY CALCULATOR WORKS FINE EXCEPT FOR THIS PART BELOW :
Your calculator's behavior should pretty much behave like the Windows Calculator in Standard mode. In Standard mode, the order that operations are evaluated is that in which they are entered. For example, if the users presses "3", "+", "2", and "*", the display gets the value of the first operation (3+2). Subsequently pressing "4" and "=" results in the running total (4) getting multiplied by 4, yielding 20. If multiple operators are input in succession, use the last one for computation.
CAN SOMEONE PLEASE HELP ME! THIS IS MY CODE:
using System;
using System.Collections.Generic
;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Calculator
{
public partial class calculatorForm : Form
{
bool add = false;
bool sub = false;
bool multiply = false;
bool divide = false;
bool equal = false;
public calculatorForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn1_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "1";
}
private void CheckifEqual()
{
if (equal)
{
textBox1.Text = "";
equal = false;
}
}
private void btn0_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "0";
}
private void btn4_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "4";
}
private void btn7_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "7";
}
private void btm8_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "8";
}
private void btn5_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "5";
}
private void btn2_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "2";
}
private void btn3_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "3";
}
private void btn6_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "6";
}
private void btn9_Click(object sender, EventArgs e)
{
CheckifEqual();
textBox1.Text = textBox1.Text + "9";
}
private void btnDec_Click(object sender, EventArgs e)
{
CheckifEqual();
if (textBox1.Text.Contains(".
"))
{
return;
}
else
{
textBox1.Text = textBox1.Text + ".";
}
}
private void btnPlusMinus_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("-
"))
{
textBox1.Text = textBox1.Text.Remove(0, 1);
}
else
{
textBox1.Text = "-" + textBox1.Text;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
add = true;
textBox1.Tag = textBox1.Text;
textBox1.Text = "";
}
}
private void btnEqual_Click(object sender, EventArgs e)
{
equal = true;
if (add)
{
decimal dec = Convert.ToDecimal(textBox1
.Tag) + Convert.ToDecimal(textBox1
.Text);
textBox1.Text = dec.ToString();
}
if (multiply)
{
decimal dec = Convert.ToDecimal(textBox1
.Tag) * Convert.ToDecimal(textBox1
.Text);
textBox1.Text = dec.ToString();
}
if (sub)
{
decimal dec = Convert.ToDecimal(textBox1
.Tag) - Convert.ToDecimal(textBox1
.Text);
textBox1.Text = dec.ToString();
}
if (divide)
{
decimal dec = Convert.ToDecimal(textBox1
.Tag) / Convert.ToDecimal(textBox1
.Text);
textBox1.Text = dec.ToString();
}
}
private void btnSub_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
sub = true;
textBox1.Tag = textBox1.Text;
textBox1.Text = "";
}
}
private void btnMultiply_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
multiply = true;
textBox1.Tag = textBox1.Text;
textBox1.Text = "";
}
}
private void btnDivide_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
divide = true;
textBox1.Tag = textBox1.Text;
textBox1.Text = "";
}
}
private void btnClear_Click(object sender, EventArgs e)
{
add = sub = multiply = divide = equal = false;
textBox1.Text = "";
textBox1.Tag = "";
}
Answer : Help Please!
You have an extra } just above that method and you have a } missing at the end. You may have inserted your code between the wrong pair of }s.
Random Solutions
IE8 or Higher
Icons and Start menu disappeared from desktop, running Windows 7 Home Edition on a Dell
Access Report - Where Condition
setting SMTP server - please see attached file - it is not working
Accessing DOM in FF
Backbone switch best practice
Configuring logging in named.conf
How can I tied up a JQuery event after a Postback?
How to open new pdf window using struts ?
forms and cgi - calling a subroutine rather than separate cgi script