954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

The Calculator Class - Need Help

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();
            }
    }
}
tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

I've got a bit of a concern in the way the information is being passed to the calculator class and in the way the answer textbox is being populated.

First:

answerNumber = Calculator.Equals(firstNumber, secondNumber, arithmeticProcess, answerNumber);


It appears as if you're passing answerNumber to the calculator to get back a value of answerNumber. Realistically the values to be passedto the calculator should be just firstNumber, secondNumber, arithmeticProcess (and the calculator class should be adjusted to accept those 3 inputs).

Second:

txtDisplay.Text = Calculator.GetDisplayText(answerNumber);


Again it looks as though you are passing the answer back to the calculator... for it to pass you back the answer. If anything, once the calculator has passed you back the answer (via Return answerNumber in the calculator class) you should be simply transferring this value to the textBox and not passing it right back to the calculator for it to pass back as a string.

Alternate method: Instead of using a return value on the Equals process, simply store the information in the variable answerNumber within the calculator class. Then, use the GetDisplayText() process to call the locally stored answerNumber variable within it's own class and return it to you in text form for the textBox.

So... basically... I would do it one of two ways:

private void btnEquals_Click(System.Object sender, System.EventArgs e)
{
    Calculator.Equals(firstNumber, secondNumber, arithmeticProcess);
    txtDisplay.Text = Calculator.GetDisplayText();
}


Where the Equals procedure in the calculator class takes 3 variables and stores the answer within the class (no Return) and GetDisplayText takes the class-stored variable, converts it to string and returns it for the textBox.

Or...

private void btnEquals_Click(System.Object sender, System.EventArgs e)
{
    txtDisplay.Text = Convert.ToString(Calculator.Equals(firstNumber, secondNumber, arithmeticProcess));
}


Eliminating the GetDisplayText procedure alltogether.

Hope this helps :) Please mark as solved if it resolves your issue.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 

your class seems to be working... I think the problem is on how you call the class.


private void btnEquals_Click(System.Object sender, System.EventArgs e)
{

Calculator x = new Calculator();
double answerNumber;
answerNumber = x.Equals(firstNumber, secondNumber, arithmeticProcess, answerNumber);

txtDisplay.Text = Convert.ToString(x.GetDisplayText(answerNumber));

}

vsa000
Newbie Poster
20 posts since Oct 2009
Reputation Points: 11
Solved Threads: 4
 

Error 1 Member 'Project_12_1_Create_Basic_Calculator.Calculator.Equals(double, double, string, double)' cannot be accessed with an instance reference; qualify it with a type name instead


Error 2 Member 'Project_12_1_Create_Basic_Calculator.Calculator.GetDisplayText(double)' cannot be accessed with an instance reference; qualify it with a type name instead


If I make the change of
Calculator x = new Calculator();
answerNumber = x.Equals(firstNumber, secondNumber, arithmeticProcess, answerNumber);
txtDisplay.Text = x.GetDisplayText(answerNumber);

The errors above are the ones I am getting

main form btnEquals_Click code

private void btnEquals_Click(System.Object sender, System.EventArgs e)
        {
            Calculator calculator = new Calculator();
            answerNumber = calculator.Equals(firstNumber, secondNumber, arithmeticProcess, answerNumber);

            txtDisplay.Text = calculator.GetDisplayText(answerNumber);
         
        }


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();
            }
    }
}
tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

The first suggestion results in this error message:

Error 1 Use of unassigned local variable 'answerNumber'

and here is the coding for it
main form btnEquals_Click

private void btnEquals_Click(System.Object sender, System.EventArgs e)
        {
            
            txtDisplay.Text = Convert.ToString(Calculator.Equals(firstNumber, secondNumber, arithmeticProcess));
         
        }

and 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;
            
            
        }

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

           
    }
}
tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

your class seems to be working... I think the problem is on how you call the class.

private void btnEquals_Click(System.Object sender, System.EventArgs e) { Calculator x = new Calculator(); double answerNumber; answerNumber = x.Equals(firstNumber, secondNumber, arithmeticProcess, answerNumber); txtDisplay.Text = Convert.ToString(x.GetDisplayText(answerNumber)); }


I am still getting an error message, I posted in the forum, can you take a look and see what Ive done wrong. I really want to understand, but for some reason I am just very confused about this

tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

using Project_12_1_Create_Basic_Calculator; //<---- type this

private void btnEquals_Click(System.Object sender, System.EventArgs e)
{

Calculator x = new Calculator();

double answerNumber; // <- typethis (assigned local variable 'answerNumber')

answerNumber = x.Equals(22, 23, "+");

txtDisplay.Text = Convert.ToString(x.GetDisplayText(answerNumber));

}

vsa000
Newbie Poster
20 posts since Oct 2009
Reputation Points: 11
Solved Threads: 4
 

actually type using Project_12_1_Create_Basic_Calculator;

over

private btnEquals_Click(System.Object sender, System.EventArgs e)
{
}

still getting error messages....

tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

i see..hmmmm did u input a value?
ex:

answerNumber = x.Equals(22, 23, "+");

can i see the error message?

vsa000
Newbie Poster
20 posts since Oct 2009
Reputation Points: 11
Solved Threads: 4
 

I will attach the code here, It is like a windows calculator, you click the button which inputs the firstNumber, then click the arithmeticProcess such as addition, subtraction, etc then click the secondNumber, when you click the equals button, it is to return the answer from the Calculator class.....

The error messages are:


Error 1 Member 'Project_12_1_Create_Basic_Calculator.Calculator.Equals(double, double, string, double)' cannot be accessed with an instance reference; qualify it with a type name instead

and

Error 2 Member 'Project_12_1_Create_Basic_Calculator.Calculator.GetDisplayText(double)' cannot be accessed with an instance reference; qualify it with a type name instead

to avoid an overabundance of code, I will only put the btnEquals_Click code

private void btnEquals_Click(System.Object sender, System.EventArgs e)
        {
            Calculator x = new Calculator();
            double answerNumber;
            answerNumber = x.Equals(firstNumber, secondNumber, arithmeticProcess, answerNumber);
            txtDisplay.Text = Convert.ToString(x.GetDisplayText(answerNumber));
         
        }


and here is 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();
            }
    }
}


any help is appreciated, as I am a beginner at this, and very lost

tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

Ok... I was probably somewhat confusing in how I worded it the last time so here it is step by step :)

First, your program class:

Calculator newCalc = new Calculator(); //Create instance of Calculator called newCalc

private void btnEquals_Click(System.Object sender, System.EventArgs e)
    {            
        txtDisplay.Text = Convert.ToString(newCalc.Equals(firstNumber, secondNumber, arithmeticProcess));         
    }


Then 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)
        {
            
            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();
            }*/
    }
}


MOST of the stuff above the Equals procedure is unused in the way you call this class as all the variables being used in the Equals procedure are obtained by the calling of the function in the first place (ie: newCalc.Equals(firstNumber, secondNumber, arithmeticProcess);). The only needed components above the Equals function are the answerNumber declaration at the top and the constructor of:

public Calculator()
        {
        }


So... using the changes I've outlined here you should get the following result:

On clicking btnEquals you will pass local variables firstNumber, secondNumber and arithmeticProcess to the Equals procedure within the Calculator class which is represented by newClass. Equals procedure will determine the type of mathematical process needed and generate a double value of answerNumber which it will pass back to it's caller. The caller will then convert that value to a string and insert it into txtDisplay.Text.

Hope that clears it up a bit more for you :) Sorry if I was a bit confusing originally.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 

owkie give me a minute i'll figure this out..

vsa000
Newbie Poster
20 posts since Oct 2009
Reputation Points: 11
Solved Threads: 4
 
Use of unassigned local variable 'answerNumber'

Which also reminds me... answerNumber needs to be defined as a double in your Program class as well, I assumed it was declared in the excluded portion of the Program class prior to the button click event. Tho in the example I provided a moment ago, this is not required as I take the result of the Equals procedure and apply it directly to the text box.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 

still getting the same error messages...
here is the modified code

Main Form

private void btnEquals_Click(System.Object sender, System.EventArgs e)
        {
            Calculator newCalc = new Calculator();
            txtDisplay.Text = Convert.ToString(newCalc.Equals(firstNumber, secondNumber, arithmeticProcess));
         
        }


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

           
    }
}
tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

As a side note, you did an excellent job declaring methods for getting and setting the values of your class variables.

However, this is really only necessary when:Your variables are "private" or otherwise not visible outside the class
You have procedures to set/retrieve the variables

An example of using the methods you set would be:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Project_12_1_Create_Basic_Calculator
{
    public class Calculator
    {
        private string arithmeticProcess;
        private double firstNumber;
        private double secondNumber;
        private double answerNumber;
        
        public Calculator()
        {
        }

        public void setVars(double firstNum, double secondNum, string arithProc)
        {
            ArithmeticProcess = arithProc;
            FirstNumber = firstNum;
            SecondNumber = secondNum;
        }

        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 void Equals()
        {
            
            if (ArithmeticProcess == "+")
            {
                AnswerNumber = FirstNumber + SecondNumber;
                
            }
             else if (ArithmeticProcess == "-")
            {
                AnswerNumber = FirstNumber - SecondNumber;
                
            }
            else if (ArithmeticProcess == "*")
            {
               AnswerNumber = FirstNumber * SecondNumber;
                
            }
            else if (arithmeticProcess == "/")
            {
                AnswerNumber = FirstNumber / SecondNumber;
                
            }
        }

        public static string GetDisplayText()
        {
            return AnswerNumber.ToString();
        }
    }
}


make note of the CAPITAL letters vs the lower case letters. And then in the Program class:

Calculator newCalc = new Calculator();

    private void btnEquals_Click(System.Object sender, System.EventArgs e)
        {
            newCalc.setVars(firstNumber, secondNumber, arithmeticProcess);
            newCalc.Equals();
            txtDisplay.Text = Calculator.GetDisplayText();           
        }


Basically in doing this you first set the variables, then perform the calculation on the variables, then use the GetDisplayText function to return the answer.

Both this, and my 2nd post above, should work for your needs but this one actually UTILIZES the methods you've created.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 

still getting the same error messages... here is the modified code

Main Form

private void btnEquals_Click(System.Object sender, System.EventArgs e)
        {
            Calculator newCalc = new Calculator();
            txtDisplay.Text = Convert.ToString(newCalc.Equals(firstNumber, secondNumber, arithmeticProcess));
         
        }

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

           
    }
}

You've double-declared answerNumber, try just copy/pasting my prior example :)

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 
Which also reminds me... answerNumber needs to be defined as a double in your Program class as well, I assumed it was declared in the excluded portion of the Program class prior to the button click event. Tho in the example I provided a moment ago, this is not required as I take the result of the Equals procedure and apply it directly to the text box.

I hope I am not being frustrating to you, I have never had such an issue with a program before, I appreciate your patience with me.
Thank You

tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

Sry, ok... try copy/pasting the code I gave you in this post directly.

It's all your original code with my modifications so you should be able to copy from top to bottom of the Calculator class code to completely overwrite your existing Calculator class code. Use the Toggle Plain Text option to give direct access to the code without the numbers being copied too.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 

Error 1 An object reference is required for the non-static field, method, or property 'Project_12_1_Create_Basic_Calculator.Calculator.arithmeticProcess'

I end up with 18 of these errors when I copied the code, it says it for arithmeticProcess, firstNumber, secondNumber and answerNumber

tricket_7
Newbie Poster
20 posts since Jul 2010
Reputation Points: 7
Solved Threads: 0
 

one sec... I want to try it in my VS and see where I buggered it before posting again lol

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You