Hi all,
I am developing calculator app using C#.I have successfuly implemented its standard arithmetic functions but a bit trapped in implementing scientific functions such as sin,cos.tan etc.I take an operand1,then operator and finally second opernad to workout arithmetic calculations.In the very first attempt to do scientific calculation i for the sake of programme format first takes input followed by sin/cos/tan etc and then out result.
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
{
public partial class Form1 : Form
string input = string.Empty;
string operand1 = string.Empty;
string operand2 = string.Empty;
char operaton;
double result = 0.0;
public Form1()
InitializeComponent();
}
private void one_Click(object sender, EventArgs e)
this.textBox1.Text = " ";
input += "1";
this.textBox1.Text += input;
private void two_Click(object sender, EventArgs e)
input += "2";
private void three_Click(object sender, EventArgs e)
input += "3";
private void four_Click(object sender, EventArgs e)
input += "4";
private void five_Click(object sender, EventArgs e)
input += "5";
private void six_Click(object sender, EventArgs e)
input += "6";
private void seven_Click(object sender, EventArgs e)
input += "7";
private void eight_Click(object sender, EventArgs e)
input += "8";
private void nine_Click(object sender, EventArgs e)
input += "9";
private void dot_Click(object sender, EventArgs e)
input += ".";
private void zero_Click(object sender, EventArgs e)
input += "0";
private void clear_Click(object sender, EventArgs e)
this.textBox1.Text = "0";
this.input = string.Empty;
this.operand1 = string.Empty;
this.operand2 = string.Empty;
private void plus_Click(object sender, EventArgs e)
operand1 = input;
operaton = '+';
input = string.Empty;
private void minus_Click(object sender, EventArgs e)
operaton = '-';
private void mul_Click(object sender, EventArgs e)
operaton = '*';
private void div_Click(object sender, EventArgs e)
operaton = '/';
private void mod_Click(object sender, EventArgs e)
operaton = '%';
private void sine_Click(object sender, EventArgs e)
operaton = 's';
private void cosine_Click(object sender, EventArgs e)
operaton = 'c';
private void tan_Click(object sender, EventArgs e)
operaton = 't';
private void equals_Click(object sender, EventArgs e)
operand2 = input;
double num1, num2;
double.TryParse(operand1, out num1);
double.TryParse(operand2, out num2);
if (operaton == '+')
result = num1 + num2;
textBox1.Text = result.ToString();
else if (operaton == '-')
result = num1 - num2;
else if (operaton == '*')
result = num1 * num2;
else if (operaton == '/')
if (num2 != 0)
result = num1 / num2;
else
textBox1.Text = "DIV/Zero!";
else if (operaton == '%')
result = num1 % num2;
else if (operaton == 's')
int inp;
int.TryParse(operand1, out inp);
result = Math.Sin(inp);
else if (operaton == 'c')
result = Math.Cos(num1);
else if (operaton == 't')
result = Math.Tan(num1);
I want to mention here that my output for scientific functions is not correct.Also,kindly tell me error in this format as in second attempt i will convert it to standard scientific mode i.e. pressing sin/cos/tan and then operand.
Regards