|
-
February 5th, 2010, 09:42 AM
#1
Simple Calculator Problem
Hi guys I'm new to this forum.... 
I've been working with my simple calculator for almost 2 days now... I am familiar with VB.NET codes and tried to relate it with C# codes... Here is my code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace prjLabExer5
{
public partial class frmLabExer5 : Form
{
public frmLabExer5()
{
InitializeComponent();
}
string operand;
double Value1 = 0;
double Value2 = 0;
//Double memory;
double ValueT = 0;
private void btn1_Click(object sender, EventArgs e)
{
txtValue.Text += "1";
}
private void btn2_Click(object sender, EventArgs e)
{
txtValue.Text += "2";
}
private void btn3_Click(object sender, EventArgs e)
{
txtValue.Text += "3";
}
private void btn4_Click(object sender, EventArgs e)
{
txtValue.Text += "4";
}
private void btn5_Click(object sender, EventArgs e)
{
txtValue.Text += "5";
}
private void btn6_Click(object sender, EventArgs e)
{
txtValue.Text += "6";
}
private void btn7_Click(object sender, EventArgs e)
{
txtValue.Text += "7";
}
private void btn8_Click(object sender, EventArgs e)
{
txtValue.Text += "8";
}
private void btn9_Click(object sender, EventArgs e)
{
txtValue.Text += "9";
}
private void btndot_Click(object sender, EventArgs e)
{
txtValue.Text += ".";
}
private void btnplus_Click(object sender, EventArgs e)
{
operand = "+";
Value1 = Convert.ToDouble(txtValue.Text);
txtValue.Clear();
}
private void btnminus_Click(object sender, EventArgs e)
{
operand = "-";
Value1 = Convert.ToDouble(txtValue.Text);
txtValue.Clear();
}
private void btnmulti_Click(object sender, EventArgs e)
{
operand = "*";
Value1 = Convert.ToDouble(txtValue.Text);
txtValue.Clear();
}
private void btndivide_Click(object sender, EventArgs e)
{
operand = "/";
Value1 = Convert.ToDouble(txtValue.Text);
txtValue.Clear();
}
private void btnequals_Click(object sender, EventArgs e)
{
Value2 = Convert.ToDouble(txtValue.Text);
switch (operand)
{
case "+":
ValueT = Value1 + Value2;
txtValue.Text = ValueT.ToString() ;
break;
case "-":
ValueT = Value1 - Value2;
txtValue.Text = ValueT.ToString();
break;0
case "*":
ValueT = Value1 * Value2;
txtValue.Text = ValueT.ToString();
break;
case "/":
if (Value2 == 0)
{
txtValue.Text = "Infinity";
}
else if (Value2 != 0)
{
ValueT = Value1 / Value2;
txtValue.Text = ValueT.ToString();
}
break;
}
}
}
}
This program cannot display the result on the textbox... I dont know what I'm missing... please help me guys.... Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|