I guess my hurdle i am trying to get over, making a calculator like windows pretty much, using only 1 text box, when a user clicks on button, 1, and shows up number 1 in text box, but getting it to click on a equation and then a number is a mystery to me, like how do they collect data provided by 1 text box? I have the code so far from what i got but i know i am doing something wrong, i hope this helps the confusion.
Code:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
numbers num = new numbers();
public Form1()
{
InitializeComponent();
}
enum operation
{
add,
subtract,
divide,
multiply
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnclear_Click(object sender, EventArgs e)
{
num.numbering = 0;
}
private void txtbox1_TextChanged(object sender, EventArgs e)
{
}
private bool firstNumberSet = false;
private void btn1_Click(object sender, EventArgs e)
{
try
{
if (!firstNumberSet)
{
num.numbering = 1;
}
else
{
num.numbering2 = 2;
}
txtbox1.Text += "1";
}
catch(Exception)
{
MessageBox.Show("WHAT DID YOU DO!!");
}
}
private void btn2_Click(object sender, EventArgs e)
{
num.numbering = 2;
txtbox1.Text += "2";
}
private void btn3_Click(object sender, EventArgs e)
{
num.numbering = 3;
txtbox1.Text += "3";
}
private void btn4_Click(object sender, EventArgs e)
{
num.numbering = 4;
txtbox1.Text += "4";
}
private void btn5_Click(object sender, EventArgs e)
{
num.numbering = 5;
txtbox1.Text += "5";
}
private void btn6_Click(object sender, EventArgs e)
{
num.numbering = 6;
txtbox1.Text += "6";
}
private void btn7_Click(object sender, EventArgs e)
{
num.numbering = 7;
txtbox1.Text += "7";
}
private void btn8_Click(object sender, EventArgs e)
{
num.numbering = 8;
txtbox1.Text += "8";
}
private void btn9_Click(object sender, EventArgs e)
{
num.numbering = 9;
txtbox1.Text += "9";
}
private void btn0_Click(object sender, EventArgs e)
{
num.numbering = 0;
txtbox1.Text += "0";
}
operation currentOperation;
operation currentOperationminus;
operation currentOperationmult;
operation currentOperationdiv;
private void btnplus_Click(object sender, EventArgs e)
{
currentOperation = operation.add;
firstNumberSet = true; // this is where we decide that the first number is done and we should
//start on the second one
}
private void btnsubtract_Click(object sender, EventArgs e)
{
currentOperationminus = operation.subtract;
firstNumberSet = true;
}
private void btnmultiply_Click(object sender, EventArgs e)
{
currentOperationmult = operation.multiply;
firstNumberSet = true;
}
private void btndivide_Click(object sender, EventArgs e)
{
currentOperationmult = operation.divide;
firstNumberSet = true;
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
aboutfrm bout = new aboutfrm();
bout.Show();
}
private void btnequal_Click(object sender, EventArgs e)
{
numbers num = new numbers();
Equations equat = new Equations();
switch (currentOperation)
{
case operation.add:
equat.add(num.numbering, num.numbering2);
break;
case operation.subtract:
equat.subtract(num.numbering, num.numbering2);
break;
case operation.multiply:
equat.mulitply(num.numbering, num.numbering2);
break;
case operation.divide:
equat.divide(num.numbering, num.numbering2);
break;
}
}
}
}
and here is my two classes which first class is numbers:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
class numbers
{
private double number;
private double number2;
public double numbering
{
get { return number; }
set
{
number = number * 10; // this will move the other digits left one
number += value; // this puts the new one in the ones column
}
}
public double numbering2
{
get { return number2; }
set
{
number2 = number2 * 10; // this will move the other digits left one
number2 += value; // this puts the new one in the ones column
}
}
}
}
second class equations:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
class Equations
{
public double add(double num1, double num2)
{
return num1 + num2;
}
public double subtract(double num1, double num2)
{
return num1 - num2;
}
public double mulitply(double num1, double num2)
{
return num1 * num2;
}
public double divide(double num1, double num2)
{
return num1 / num2;
}
}
}
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum