Hey guys,
I am new to C# and Object Oriented Programming,
I got this calculator code which was designed in Visual Studio 2008 and I am getting an error with
isZero == false
"Error Only assignment, call, increment, decrement, and new object expressions can be used as a statement."
Also if I remove the
isZero == false
I get an error saying that "Error Program 'C:\Users\Jordan McGehee\Documents\Visual Studio 2008\Projects\Calculator\Calculator\obj\Debug\Calculator.exe' does not contain a static 'Main' method suitable for an entry point"
Below is the code and I have attached project file
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 Form1 : Form
{
public Form1()
{
InitializeComponent();
isZero = true;
}
string oper;
bool isZero;
private void btnClear_Click(object sender, EventArgs e)
{
txtCalculatorWindow.Text = "";
}
private void btn1_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn2_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn3_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn4_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn5_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn6_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn7_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn8_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn9_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btn0_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
private void btnAdd_Click(object sender, EventArgs e)
{
oper = "+";
}
private void btnSubtract_Click(object sender, EventArgs e)
{
oper = "-";
}
private void btnMultiply_Click(object sender, EventArgs e)
{
oper = "*";
}
private void btnDivide_Click(object sender, EventArgs e)
{
oper = "/";
}
private void btnEquals_Click(object sender, EventArgs e)
{
double res = 0;
switch (oper)
{
case "+":
res = Convert.ToDouble(txtCalculatorWindow.Text);
break;
case "-":
res = Convert.ToDouble(txtCalculatorWindow.Text);
break;
case "*":
res = Convert.ToDouble(txtCalculatorWindow.Text);
break;
case "\\":
if (txtCalculatorWindow.Text == "0")
txtCalculatorWindow.Text = "Error";
else
res = Convert.ToDouble(txtCalculatorWindow.Text);
break;
}
}
private void btnDecimal_Click(object sender, EventArgs e)
{
Button ClickedButton = (Button)sender;
if (isZero == true)
{
txtCalculatorWindow.Text = ClickedButton.Text;
isZero == false
}
else
txtCalculatorWindow.Text += ClickedButton.Text;
}
}
}