1

So you got it working now? Which version did you use in the end? the version that utilizes the methods and private variables in the Calculator class? or the version that directly derives the answer from the Equals procedure?

Oh, and if it's solved, please remember to mark the thread as solved as well :P

Votes + Comments
Help was thorough, and helped me to also understand what I was doing.
0

And the solution that worked is.....
main form

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

        private void btnAdd_Click(System.Object sender, System.EventArgs e)
        {
            firstNumber = Double.Parse(txtDisplay.Text);
            secondNumber = Double.Parse(txtDisplay.Text);
            txtDisplay.Clear();
            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
    {
        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 void Equals()
        {

            if (arithmeticProcess == "+")
            {
                answerNumber = firstNumber + secondNumber;

            }
            else if (arithmeticProcess == "-")
            {
                answerNumber = secondNumber - firstNumber;

            }
            else if (arithmeticProcess == "*")
            {
                answerNumber = firstNumber * secondNumber;

            }
            else if (arithmeticProcess == "/")
            {
                answerNumber = secondNumber / firstNumber;

            }
           
        }

        public string GetDisplayText()
        {
            return answerNumber.ToString();
        }
    }
}
0

hi can someone help me to make a calculator as required?
Create class Calculator. This class must contain the following features:

constant PI
constructor that accepts two integers, operand1 and operand2
method for writing values ​​and operand2 operand1
methods for calculating the four operations - addition, subtraction, division and multiplication that will return the result of operand1 and operand2 operation on values
static methods for these operations, which accepts parameters as operands
method that calculates the surface area of the circle diameter circle operand1.
Create a console application that instantiates object of class Calculator, call all the methods and write the result of calculation.
pls thanks
sorry for my bad english

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.