sanddy1911
New member
- Joined
- Dec 7, 2014
- Messages
- 1
- Programming Experience
- Beginner
I'm new to c# and try to make a Basic calculator this is how far I came
i'm getting unexpected results can anyone help me.
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public partial class Calculator : Form
{
private int firstValue =0;
private int secondValue =0;
private char opration = '0';
public Calculator()
{
InitializeComponent();
}
private void Calculator_Load(object sender, EventArgs e)
{
//txtDisplay.Text = "0";
}
private void btn1_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "1");
}
private void btn2_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "2");
}
private void btn3_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "3");
}
private void btn4_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "4");
}
private void btn5_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "5");
}
private void btn6_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "6");
}
private void btn7_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "7");
}
private void btn8_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "8");
}
private void btn9_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text.Insert(txtDisplay.TextLength, "9");
}
private void btnPlus_Click(object sender, EventArgs e)
{
firstValue =+ Convert.ToInt32(txtDisplay.Text);
opration = '+';
txtDisplay.Text = "";
}
private void btnMinus_Click(object sender, EventArgs e)
{
firstValue =- Convert.ToInt32(txtDisplay.Text);
opration = '-';
txtDisplay.Text = "";
}
private void btnMulti_Click(object sender, EventArgs e)
{
firstValue *= Convert.ToInt32(txtDisplay.Text);
opration = '*';
txtDisplay.Text = "";
}
private void btnDiv_Click(object sender, EventArgs e)
{
firstValue /= Convert.ToInt32(txtDisplay.Text);
opration = '/';
txtDisplay.Text = "";
}
private void btnCLear_Click(object sender, EventArgs e)
{
txtDisplay.Text = "";
firstValue = 0;
secondValue = 0;
opration = '0';
}
private void btnEqual_Click(object sender, EventArgs e)
{
switch (opration)
{
case '+':
firstValue += Convert.ToInt32(txtDisplay.Text);
txtDisplay.Text = firstValue.ToString();
break;
case '-':
firstValue -= Convert.ToInt32(txtDisplay.Text);
txtDisplay.Text = firstValue.ToString();
break;
case '*':
firstValue *= Convert.ToInt32(txtDisplay.Text);
txtDisplay.Text = firstValue.ToString();
break;
case '/':
firstValue /= Convert.ToInt32(txtDisplay.Text);
txtDisplay.Text = firstValue.ToString();
break;
default:
break;
}
}
}
}
i'm getting unexpected results can anyone help me.