C# Calculator. Can’t figure out how to store values in variables!

The code consists of two files, the executable form and a class. The class 'Calculator' is where I intend to store the entered values. The variables in the class are "double first, double second, string op, bool change". The variables first and second should store the entered values on the calculator, op is the operation which is to be used with first and second. And finally change is the bool that's intended to alter which variable (between first and second) is being currently changed.

I cannot figure out what I'm supposed to do to be able to modify these variables. I've managed to take the unaltered variables from the class file and made them accessible using what I named kalkylator. And although they're accessible I don't know how to change their stored values.

Hopefully this hasn't all been nonsense and my ideas are comprehensible. I'm still not all too familiar with the programming language so pardon me for having the vocabulary of an infant.

Here's the code divided into two segments, one representing each file.

public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void form1_Load(object sender, EventArgs e) { Calculator kalkylator = new Calculator(); kalkylator.SetFirstOperand(0.0); kalkylator.SetSecondOperand(0.0); kalkylator.SetOP(""); kalkylator.SetChange(false); } private void button_Click_Click(object sender, EventArgs e) // Value - Press a number or , on the calculator and the digit appears in the textbox { Button k = (Button)sender; tbxEntry.Text = tbxEntry.Text + k.Text; } private void button19_Click(object sender, EventArgs e) // C - clears the current entry { tbxEntry.Text = null; } private void button14_Click(object sender, EventArgs e) // Operator - Press an operator on the calculator and said operator appears. Intended to be used with Bool to alter between two variables to store // two different values which will be calculated. { Button k = (Button)sender; tbxEntry.Text = tbxEntry.Text + k.Text; } } 


class Calculator { private double first;//första operand public void SetFirstOperand (double first) { this.first = first; } public double GetFirstOperand () { return this.first; } private double second;//andra operand public void SetSecondOperand (double second) { this.second = second; } public double GetSecondOperand () { return this.second; } private string op; //operator public void SetOP(string op) { this.op = op; } public string GetOP() { return this.op; } private bool change; public void SetChange(bool change) { this.change = change; } public bool GetChange() { return this.change; } } 


Edit: Formatting

by lantsen via /r/csharp

Leave a Reply