nayak army

nayak army

  • NA
  • 14
  • 3.3k

percentage code in c# for calculator:

Sep 21 2015 7:52 AM
i got error found in percentage ,so pls solve my error,i have great hope on u. 
 
i  placed here my totally code ,for explain u.'
so please refer my code & get help for me found percentage in this calculator. 
 
 
 
default.aspx
 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Calcy.aspx.cs" Inherits="Calcy" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="SctriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="upnlCalcy" runat="server">
<ContentTemplate>
<table border="1" bgcolor="Pink">
<tr>
<td>
<asp:TextBox ID="txtAns" runat="server" Width="343" Height="50" Font-Size="Larger" ReadOnly="True"></asp:TextBox><br /><br />
<asp:TextBox ID="TextBox2" runat="server" Width="343" Height="50" Font-Size="Small" ReadOnly="true"></asp:TextBox>
</td>
</tr>
<tr>
<td><br />
<asp:Button ID="btnBack" runat="server" Text="Backspace" Width="132" Height="50" BackColor="White" BorderColor="Black" OnClick="btnBack_Click" />&nbsp;&nbsp;
<asp:Button ID="btnClear" runat="server" Text="Clear" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnClear_Click" />&nbsp;&nbsp;
<asp:Button ID="btnCE" runat="server" Text="CE" Width="132" Height="50" BackColor="White" BorderColor="Black" OnClick="btnCE_Click" />
</td>
</tr>
<tr>
<td><br />
<asp:Button ID="btn7" runat="server" Text="7" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn7_Click" />&nbsp;&nbsp;
<asp:Button ID="btn8" runat="server" Text="8" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn8_Click" />&nbsp;&nbsp;
<asp:Button ID="btn9" runat="server" Text="9" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn9_Click" />&nbsp;&nbsp;
<asp:Button ID="btnDiv" runat="server" Text="/" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnDiv_Click" />&nbsp;&nbsp;
<asp:Button ID="btnPercentage" runat="server" Text="%" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnPercentage_Click" />
</td>
</tr>
<tr>
<td><br />
<asp:Button ID="btn4" runat="server" Text="4" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn4_Click" />&nbsp;&nbsp;
<asp:Button ID="btn5" runat="server" Text="5" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn5_Click" />&nbsp;&nbsp;
<asp:Button ID="btn6" runat="server" Text="6" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn6_Click" />&nbsp;&nbsp;
<asp:Button ID="btnMul" runat="server" Text="*" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnMul_Click" />&nbsp;&nbsp;
<asp:Button ID="btnSqrt" runat="server" Text="SQRT" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnSqrt_Click" />
</td>
</tr>
<tr>
<td><br />
<asp:Button ID="btn1" runat="server" Text="1" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn1_Click" />&nbsp;&nbsp;
<asp:Button ID="btn2" runat="server" Text="2" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn2_Click" />&nbsp;&nbsp;
<asp:Button ID="btn3" runat="server" Text="3" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn3_Click" />&nbsp;&nbsp;
<asp:Button ID="btnSub" runat="server" Text="-" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnSub_Click" />&nbsp;&nbsp;
<asp:Button ID="btn1byx" runat="server" Text="1/x" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn1byx_Click" />
</td>
</tr>
<tr>
<td><br />
<asp:Button ID="btn0" runat="server" Text="0" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btn0_Click" />&nbsp;&nbsp;
<asp:Button ID="btnDot" runat="server" Text="." Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnDot_Click" />&nbsp;&nbsp;
<asp:Button ID="btnEqual" runat="server" Text="=" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnEqual_Click" />&nbsp;&nbsp;
<asp:Button ID="btnAdd" runat="server" Text="+" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnAdd_Click" />&nbsp;&nbsp;
<asp:Button ID="btnPlusMinus" runat="server" Text="+/-" Width="60" Height="50" BackColor="White" BorderColor="Black" OnClick="btnPlusMinus_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Calcy : System.Web.UI.Page
{
    int a;
    
    //int result;


    //int value1;
    //int percentage; 


    int count;
    int totalcount;


    decimal val1;
    decimal val2;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        int d;
        d = txtAns.Text.Length;
        txtAns.Text = txtAns.Text.Remove(d - 1, 1);
        TextBox2.Text = TextBox2.Text.Remove(d - 1, 1);
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        txtAns.Text = "";
        TextBox2.Text = "";
    }
    protected void btnCE_Click(object sender, EventArgs e)
    {
        txtAns.Text = txtAns.Text + "";
        txtAns.Text = "";
        TextBox2.Text = "";
    }
    protected void btn7_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn7.Text;
        TextBox2.Text += txtAns.Text;
        
    }
    protected void btn8_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn8.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn9_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn9.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn4_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn4.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn5_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn5.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn6_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn6.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn1_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn1.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn2_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn2.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn3_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn3.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn0_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn0.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btnDot_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btnDot.Text;
        TextBox2.Text += txtAns.Text;
        
    }
    protected void btnEqual_Click(object sender, EventArgs e)
    {
        string str = txtAns.Text;
        object obj;
        DataTable dt = new DataTable();
        obj = dt.Compute(str, null);
        txtAns.Text = obj.ToString();
        TextBox2.Text = "";
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnAdd.Text;
        TextBox2.Text = "";
    }
    protected void btnSub_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = TextBox2.Text + btnSub.Text;
        TextBox2.Text = "";
    }
    protected void btnMul_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnMul.Text;
        //TextBox2.Text = "";
    }
    protected void btnDiv_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnDiv.Text;
        TextBox2.Text = "";
    }
    protected void btnPlusMinus_Click(object sender, EventArgs e)
    {
        a = 0;
        decimal currVal = decimal.Parse(txtAns.Text);
        currVal = -currVal;
        txtAns.Text = currVal.ToString();
        TextBox2.Text = "";
    }
    protected void btn1byx_Click(object sender, EventArgs e)
    {
        a = 0;
        decimal value = decimal.Parse(txtAns.Text);
        value = 1 / value;
        txtAns.Text = value.ToString();
        TextBox2.Text = "";
    }
    protected void btnSqrt_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = Math.Sqrt(Convert.ToDouble(txtAns.Text)).ToString();
        TextBox2.Text = "";
    }



    protected void btnPercentage_Click(object sender, EventArgs e)
    {
        //double percentage = (double.Parse(txtAns.Text) * double.Parse(txtAns.Text)) / 100;
        //txtAns.Text = percentage.ToString();


        //a = 0;
        //value = Convert.ToInt32(txtAns.Text);
        //result = Convert.ToInt32(value * value);
        //txtAns.Text = result.ToString();
        //display = double.Parse(TextBox2.Text);
        //decimal value1 = decimal.Parse(txtAns.Text);
        //txtAns.Text = (value * display).ToString();
        ////txtAns.Text = value.ToString();
        ////txtAns.Text = value1.ToString();
        //a = 0;
        //percentage = (Convert.ToInt32(txtAns.Text) * Convert.ToInt32(txtAns.Text)).ToString();

        //a = 0;
        //double value = double.Parse(txtAns.Text);
        //double percentage = 0.01;

        //double comission = value * percentage;

        //txtAns.Text = comission.ToString();
        //TextBox2.Text = "";

        //Double a = no1;
        //Double b = no2;
        
        //Double percentage = (a * b / 100);

        //// to output the result
        //txtAns.Text = percentage.ToString().Trim();
      //  txtAns.Text = (value1 * percentage / 100).ToString();

        //var result = (percentage / 100) * value1;
        //txtAns.Text = result.ToString();

        //if (a == 0)
        //{
        //    TextBox2.Text = "";
        //    a = 1;

        //}
      //  txtAns.Text = ((percentage * .01) * value1).ToString();



        //count = ((count * 100) / totalcount);
        //txtAns.Text = count.ToString().Trim();

        //if (txtAns.Text != string.Empty)
        //{

        //    double chk = Convert.ToDouble("1") / Convert.ToDouble(txtAns.Text);

        //    txtAns.Text = chk.ToString();

        //}

        

        txtAns.Text = Convert.ToString(Convert.ToInt32(val1) * Convert.ToInt32(val2) / 100);



    }




}using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Calcy : System.Web.UI.Page
{
    int a;
    
    //int result;


    //int value1;
    //int percentage; 


    int count;
    int totalcount;


    decimal val1;
    decimal val2;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        int d;
        d = txtAns.Text.Length;
        txtAns.Text = txtAns.Text.Remove(d - 1, 1);
        TextBox2.Text = TextBox2.Text.Remove(d - 1, 1);
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        txtAns.Text = "";
        TextBox2.Text = "";
    }
    protected void btnCE_Click(object sender, EventArgs e)
    {
        txtAns.Text = txtAns.Text + "";
        txtAns.Text = "";
        TextBox2.Text = "";
    }
    protected void btn7_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn7.Text;
        TextBox2.Text += txtAns.Text;
        
    }
    protected void btn8_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn8.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn9_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn9.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn4_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn4.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn5_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn5.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn6_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn6.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn1_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn1.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn2_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn2.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn3_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn3.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn0_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn0.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btnDot_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btnDot.Text;
        TextBox2.Text += txtAns.Text;
        
    }
    protected void btnEqual_Click(object sender, EventArgs e)
    {
        string str = txtAns.Text;
        object obj;
        DataTable dt = new DataTable();
        obj = dt.Compute(str, null);
        txtAns.Text = obj.ToString();
        TextBox2.Text = "";
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnAdd.Text;
        TextBox2.Text = "";
    }
    protected void btnSub_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = TextBox2.Text + btnSub.Text;
        TextBox2.Text = "";
    }
    protected void btnMul_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnMul.Text;
        //TextBox2.Text = "";
    }
    protected void btnDiv_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnDiv.Text;
        TextBox2.Text = "";
    }
    protected void btnPlusMinus_Click(object sender, EventArgs e)
    {
        a = 0;
        decimal currVal = decimal.Parse(txtAns.Text);
        currVal = -currVal;
        txtAns.Text = currVal.ToString();
        TextBox2.Text = "";
    }
    protected void btn1byx_Click(object sender, EventArgs e)
    {
        a = 0;
        decimal value = decimal.Parse(txtAns.Text);
        value = 1 / value;
        txtAns.Text = value.ToString();
        TextBox2.Text = "";
    }
    protected void btnSqrt_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = Math.Sqrt(Convert.ToDouble(txtAns.Text)).ToString();
        TextBox2.Text = "";
    }



    protected void btnPercentage_Click(object sender, EventArgs e)
    {
        //double percentage = (double.Parse(txtAns.Text) * double.Parse(txtAns.Text)) / 100;
        //txtAns.Text = percentage.ToString();


        //a = 0;
        //value = Convert.ToInt32(txtAns.Text);
        //result = Convert.ToInt32(value * value);
        //txtAns.Text = result.ToString();
        //display = double.Parse(TextBox2.Text);
        //decimal value1 = decimal.Parse(txtAns.Text);
        //txtAns.Text = (value * display).ToString();
        ////txtAns.Text = value.ToString();
        ////txtAns.Text = value1.ToString();
        //a = 0;
        //percentage = (Convert.ToInt32(txtAns.Text) * Convert.ToInt32(txtAns.Text)).ToString();

        //a = 0;
        //double value = double.Parse(txtAns.Text);
        //double percentage = 0.01;

        //double comission = value * percentage;

        //txtAns.Text = comission.ToString();
        //TextBox2.Text = "";

        //Double a = no1;
        //Double b = no2;
        
        //Double percentage = (a * b / 100);

        //// to output the result
        //txtAns.Text = percentage.ToString().Trim();
      //  txtAns.Text = (value1 * percentage / 100).ToString();

        //var result = (percentage / 100) * value1;
        //txtAns.Text = result.ToString();

        //if (a == 0)
        //{
        //    TextBox2.Text = "";
        //    a = 1;

        //}
      //  txtAns.Text = ((percentage * .01) * value1).ToString();



        //count = ((count * 100) / totalcount);
        //txtAns.Text = count.ToString().Trim();

        //if (txtAns.Text != string.Empty)
        //{

        //    double chk = Convert.ToDouble("1") / Convert.ToDouble(txtAns.Text);

        //    txtAns.Text = chk.ToString();

        //}

        

        txtAns.Text = Convert.ToString(Convert.ToInt32(val1) * Convert.ToInt32(val2) / 100);



    }


default.aspx.cs

}using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Calcy : System.Web.UI.Page
{
    int a;
    
    //int result;


    //int value1;
    //int percentage; 


    int count;
    int totalcount;


    decimal val1;
    decimal val2;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        int d;
        d = txtAns.Text.Length;
        txtAns.Text = txtAns.Text.Remove(d - 1, 1);
        TextBox2.Text = TextBox2.Text.Remove(d - 1, 1);
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        txtAns.Text = "";
        TextBox2.Text = "";
    }
    protected void btnCE_Click(object sender, EventArgs e)
    {
        txtAns.Text = txtAns.Text + "";
        txtAns.Text = "";
        TextBox2.Text = "";
    }
    protected void btn7_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn7.Text;
        TextBox2.Text += txtAns.Text;
        
    }
    protected void btn8_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn8.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn9_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn9.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn4_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn4.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn5_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn5.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn6_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn6.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn1_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn1.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn2_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn2.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn3_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn3.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btn0_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btn0.Text;
        TextBox2.Text += txtAns.Text;
    }
    protected void btnDot_Click(object sender, EventArgs e)
    {
        if (a == 0)
        {
            TextBox2.Text = "";
            a = 1;
        }
        txtAns.Text = txtAns.Text + btnDot.Text;
        TextBox2.Text += txtAns.Text;
        
    }
    protected void btnEqual_Click(object sender, EventArgs e)
    {
        string str = txtAns.Text;
        object obj;
        DataTable dt = new DataTable();
        obj = dt.Compute(str, null);
        txtAns.Text = obj.ToString();
        TextBox2.Text = "";
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnAdd.Text;
        TextBox2.Text = "";
    }
    protected void btnSub_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = TextBox2.Text + btnSub.Text;
        TextBox2.Text = "";
    }
    protected void btnMul_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnMul.Text;
        //TextBox2.Text = "";
    }
    protected void btnDiv_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = txtAns.Text + btnDiv.Text;
        TextBox2.Text = "";
    }
    protected void btnPlusMinus_Click(object sender, EventArgs e)
    {
        a = 0;
        decimal currVal = decimal.Parse(txtAns.Text);
        currVal = -currVal;
        txtAns.Text = currVal.ToString();
        TextBox2.Text = "";
    }
    protected void btn1byx_Click(object sender, EventArgs e)
    {
        a = 0;
        decimal value = decimal.Parse(txtAns.Text);
        value = 1 / value;
        txtAns.Text = value.ToString();
        TextBox2.Text = "";
    }
    protected void btnSqrt_Click(object sender, EventArgs e)
    {
        a = 0;
        txtAns.Text = Math.Sqrt(Convert.ToDouble(txtAns.Text)).ToString();
        TextBox2.Text = "";
    }



    protected void btnPercentage_Click(object sender, EventArgs e)
    {
        //double percentage = (double.Parse(txtAns.Text) * double.Parse(txtAns.Text)) / 100;
        //txtAns.Text = percentage.ToString();


        //a = 0;
        //value = Convert.ToInt32(txtAns.Text);
        //result = Convert.ToInt32(value * value);
        //txtAns.Text = result.ToString();
        //display = double.Parse(TextBox2.Text);
        //decimal value1 = decimal.Parse(txtAns.Text);
        //txtAns.Text = (value * display).ToString();
        ////txtAns.Text = value.ToString();
        ////txtAns.Text = value1.ToString();
        //a = 0;
        //percentage = (Convert.ToInt32(txtAns.Text) * Convert.ToInt32(txtAns.Text)).ToString();

        //a = 0;
        //double value = double.Parse(txtAns.Text);
        //double percentage = 0.01;

        //double comission = value * percentage;

        //txtAns.Text = comission.ToString();
        //TextBox2.Text = "";

        //Double a = no1;
        //Double b = no2;
        
        //Double percentage = (a * b / 100);

        //// to output the result
        //txtAns.Text = percentage.ToString().Trim();
      //  txtAns.Text = (value1 * percentage / 100).ToString();

        //var result = (percentage / 100) * value1;
        //txtAns.Text = result.ToString();

        //if (a == 0)
        //{
        //    TextBox2.Text = "";
        //    a = 1;

        //}
      //  txtAns.Text = ((percentage * .01) * value1).ToString();



        //count = ((count * 100) / totalcount);
        //txtAns.Text = count.ToString().Trim();

        //if (txtAns.Text != string.Empty)
        //{

        //    double chk = Convert.ToDouble("1") / Convert.ToDouble(txtAns.Text);

        //    txtAns.Text = chk.ToString();

        //}

        

        txtAns.Text = Convert.ToString(Convert.ToInt32(val1) * Convert.ToInt32(val2) / 100);



    }




}
 
 
 
 
 
 
 

Answers (4)