I am working on this visual studio 2008 calculator in c#. The calculator seems to be working, but when I created the Calculator Class, now it does not compute. I can click the number buttons, and they show up, but when I hit equals I just get a zero.
Can someone help me to get this class right. I know I have done something wrong, but as a beginner I have no clue
main form code snippet of click_equals
private void btnEquals_Click(System.Object sender, System.EventArgs e)
{
answerNumber = Calculator.Equals(firstNumber, secondNumber, arithmeticProcess, answerNumber);
txtDisplay.Text = Calculator.GetDisplayText(answerNumber);
}
and the code for the Calculator Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project_12_1_Create_Basic_Calculator
{
public class Calculator
{
public string arithmeticProcess;
public double firstNumber;
public double secondNumber;
public double answerNumber;
public Calculator()
{
}
public Calculator(string arithmeticProcess, double firstNumber, double secondNumber, double answerNumber)
{
this.FirstNumber = firstNumber;
this.ArithmeticProcess = arithmeticProcess;
this.SecondNumber = secondNumber;
this.answerNumber = answerNumber;
}
public string ArithmeticProcess
{
get
{
return arithmeticProcess;
}
set
{
arithmeticProcess = value;
}
}
public double FirstNumber
{
get
{
return firstNumber;
}
set
{
firstNumber = value;
}
}
public double SecondNumber
{
get
{
return secondNumber;
}
set
{
secondNumber = value;
}
}
public double AnswerNumber
{
get
{
return answerNumber;
}
set
{
answerNumber = value;
}
}
public static double Equals(double firstNumber, double secondNumber, string arithmeticProcess, double answerNumber)
{
if (arithmeticProcess == "+")
{
answerNumber = firstNumber + secondNumber;
}
else if (arithmeticProcess == "-")
{
answerNumber = firstNumber - secondNumber;
}
else if (arithmeticProcess == "*")
{
answerNumber = firstNumber * secondNumber;
}
else if (arithmeticProcess == "/")
{
answerNumber = firstNumber / secondNumber;
}
return answerNumber;
}
public static string GetDisplayText(double answerNumber)
{
return answerNumber.ToString();
}
}
}