-3

// THIS IS MY CODE FOR CALCULATOR BUT I HAVE PROBLEM IT CANNOT PERCENTAGE AND SQRT PLEAS HELP ME

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyCalculator
{
    public partial class calculator3 : Form
    {
        /******************=========================******************
         * creat bool for all btn(plus,minus,multiply,divid,and equal)
         * ********************and make it all false******************
         *****************==========================******************
         * */

        bool plus = false;
        bool minus = false;
        bool multiply = false;
        bool divid = false;
        bool equal = false;
        bool percentage = false;

        public calculator3()
        {
            InitializeComponent();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
        /****************==========================************
         *Now make if condition that:-xxxxxxxxxxxxxxxxxxxxxxxxz                       
         * if user hit the div,plus,multiply or divisin button 
         * veriable do some one for user as wish and it clear the 
         * Textbox for entry New value of calculation 
         * *************===========================************
         */

        private void btndivision_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                divid = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";


            }
        }

        private void btnmultiply_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                multiply = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";
            }
        }
        private void btnminus_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                minus = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";
            }
        }
        private void btnplus_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                plus = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";
            }



        }
        private void btnequal_Click(object sender, EventArgs e)
        {
            /*++++++++++++++++++xxxxxxxxxxxxxxxxxxxxxx++++++++++++++++++++++
             * This is Equal button code 
             * it work as below 
             * user hit 2 + 2 when the user hit = the code of plus will very
             *+++++++++++++++++xxxxxxxxxxxxxxxxxxxxxxx+++++++++++++++++++++++
             **/
            equal = true;

            if (plus)
            {
                decimal dec = Convert.ToDecimal(textBox1.Tag) + Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();
            }
            if (multiply)
            {
                decimal dec = Convert.ToDecimal(textBox1.Tag) * Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();
            }
            if (minus)
            {
                decimal dec = Convert.ToDecimal(textBox1.Tag) - Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();
            }
            if (divid)
            {
                decimal dec = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text);
                textBox1.Text = dec.ToString();
            }
             
            
        }

       
        
        private void button11_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "0";
        }

        private void button10_Click(object sender, EventArgs e)
        {

            checkifequal();
            textBox1.Text = textBox1.Text + "1";
        }
        /**
         * *****************======================*****************************
        ************ create own method for this code below***************
        if(equal)then textbox1.text = ""; 
        equal = false
        simply to creat method type   checkifequal()
        and when it show red error just right click it and click Generat method 
         ****************************=====================**********************
        */


        private void checkifequal()
        {
            if (equal)
            {
                textBox1.Text = "";
                equal = false;
            }
        }
        private void button14_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "2";
        }

        private void button18_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "3";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "4";
        }

        private void button13_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "5";
        }

        private void button19_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "6";
        }

        private void button8_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "7";
        }

        private void button12_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "8";
        }

        private void button16_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + "9";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            /* 
             * false all the veriable for make Textbox1 clear 
             **/

            plus = minus = multiply = divid = false;
            textBox1.Text = "";
            textBox1.Tag = "";
        }
        private void calculator3_Load(object sender, EventArgs e)
        {
            MaximizeBox = false;



        }
        private void button17_Click(object sender, EventArgs e)
        {
            checkifequal();
            textBox1.Text = textBox1.Text + ".";
        }

        private void BTNPERCENTAGE_Click(object sender, EventArgs e)
        {
        }
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void newCalcToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void simpleCalculatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BackColor = Color.LightGray;

        }

        private void scinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Width = 260;

        }

        private void scientificToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Width = 398;

        }
        /*chang color of form and button for change color action
         * 
         */

        private void dynamicCalculatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BackColor = Color.Gray;
            btn0.ForeColor = Color.Snow;
            btn1.ForeColor = Color.Snow;
            btn2.ForeColor = Color.Snow;
            btn3.ForeColor = Color.Snow;
            btn4.ForeColor = Color.Snow;
            btn5.ForeColor = Color.Snow;
            btn6.ForeColor = Color.Snow;
            btn7.ForeColor = Color.Snow;
            btn8.ForeColor = Color.Snow;
            btn9.ForeColor = Color.Snow;
            btndivision.ForeColor = Color.Snow;
            btndot.ForeColor = Color.Snow;
            btnhalf.ForeColor = Color.Snow;
            btnmultiply.ForeColor = Color.Snow;
            FunctionBtn.ForeColor = Color.Snow;
            btnplus.ForeColor = Color.Snow;
            btnsqrt.ForeColor = Color.Snow;
            button1.ForeColor = Color.Snow;
            label1.ForeColor = Color.Black;
            label1.BackColor = Color.Black;





        }

        private void btnsqrt_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                percentage = true;
                textBox1.Tag = textBox1.Text;
                textBox1.Text = "";
            }


        }
    }
    }

Edited by __avd: Added [code] tags.

Votes + Comments
Use code blocks
3
Contributors
6
Replies
9
Views
6 Years
Discussion Span
Last Post by yousafc#
0

Do not see what the problems are.
A percentage is what it says 1/100 of the value.
For Sqrt use Math.Sqrt function.
The decimal type is not the right type for doing this type of thing, use the double type. Decimal has 10^24 as maxvalue double has 10^308 as maximum.
The decimal type is always correct, that's why it is used in the banking bussiness, double can have some rounding errors.

0

Pleas checkout Red line and kindly send me percentage formula how can i declare in c#
please please i am very worried about this Please Sir

0

Did you look in the zip file in the thread I posted you, in the other thread you posted on the same subject?

0

I fact just what I said: percent comes from the Latin per centum meaning by hundred

Edited by ddanbe: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.