Hi there,
im new to c# and have been trying to create a calculator without a switch statement, using the operator 'op' as a variable, but i cannot get it to work, here is my current 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 Calculator_Neil_04._03._10
{
public partial class Form1 : Form
{
int num1 = 999;
int num2 = 999;
int result;
char op = ' ';
string num;
public Form1()
{
InitializeComponent();
}
public void procnum(char num)//please can you clarify the part in brackets, i.e. meaning
{
//op = " ";
txtbDisplay.Text = num;
if (op == ' ') //whats the difference between using ' ' or " " ??
{
num1 = num;
num1 = Convert.ToInt32(num1);
}
else
{
num2 = num;
num2 = Convert.ToInt32(num2);
}
//System.ComponentModel.Convert.DecimalConverter(op);
//op = Convert.ToDecimal(op);
result = num1 (op) num2;
txtbDisplay.Text = result.ToString();
}
private void btn7_Click(object sender, EventArgs e)
{
num = 7;
}
public void btn8_Click(object sender, EventArgs e)
{
num = 8;
}
public void btnPlus_Click(object sender, EventArgs e) //use public or private, not sure?
{
op = '+';
}
public void btnMinus_Click(object sender, EventArgs e)
{
op = '-';
}
private void btnMultiply_Click(object sender, EventArgs e)
{
op = '*';
}
private void btnDivide_Click(object sender, EventArgs e)
{
op = '/';
}
}
}
Any help would be greatly appreciated - ?