6 Replies - 110017 Views - Last Post: 30 December 2010 - 03:37 AM Rate Topic: -----

#1 abdullah_808  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-October 10

how to make an simple calculator in C#

Posted 16 October 2010 - 06:05 AM

how to make an simple calculator in C#..???simpple calculator which contains addition,multiplication,subtraction and division methods..
Is This A Good Question/Topic? 0
  • +

Replies To: how to make an simple calculator in C#

#2 mouse88  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 192
  • Joined: 27-July 10

Re: how to make an simple calculator in C#

Posted 16 October 2010 - 06:08 AM

Have you made any effort to make the calculator yet. We cant just give you the code you need to show that you have made an attempt first.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: how to make an simple calculator in C#

Posted 16 October 2010 - 06:18 AM

Didn't bother to look through the tutorials, eh?
Was This Post Helpful? 1
  • +
  • -

#4 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: how to make an simple calculator in C#

Posted 16 October 2010 - 06:22 AM

I can help you with this if you like, but do you know how to use visual studio? Do you know how to make an application and add buttons etc? Your post was abit vague.
Was This Post Helpful? 0
  • +
  • -

#5 karabasf  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 202
  • View blog
  • Posts: 417
  • Joined: 29-August 10

Re: how to make an simple calculator in C#

Posted 16 October 2010 - 06:26 AM

I think this should help you out ^^

http://www.dreaminco...ulator-in-c%23/

edit:
Bummer, someone was faster than I was

If your planning to make a GUI calculator in Visual Studio, you should find some literature (or sources) about that first ^^

This post has been edited by karabasf: 16 October 2010 - 06:28 AM

Was This Post Helpful? 1
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: how to make an simple calculator in C#

Posted 16 October 2010 - 09:02 AM

Calculator tutorial


Debugging tutorial


Quick and easy custom events
Bulding an application - Part 1
Building an application - Part 2
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Niveditha*


Reputation:

Re: how to make an simple calculator in C#

Posted 30 December 2010 - 03:37 AM

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

namespace work1
{
    public partial class Form1 : Form
    {
  
        public Form1()
        {
            InitializeComponent();
        }

        private double num1;
        private double num2;
        private string cal;
        private bool inputstatus = true;
        private void button1_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                if (textBox1.Text.Length >= 1)
                {
                    textBox1.Text += button1.Text;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button2.Text;
            }
            else
            {
                textBox1.Text = button2.Text;
                inputstatus = true;
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button3.Text;
            }
            else
            {
                textBox1.Text = button3.Text;
                inputstatus = true;
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button4.Text;
            }
            else
            {
                textBox1.Text = button4.Text;
                inputstatus = true;
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button5.Text;
            }
            else
            {
                textBox1.Text = button5.Text;
                inputstatus = true;
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button6.Text;
            }
            else
            {
                textBox1.Text = button6.Text;
                inputstatus = true;
            }

        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button7.Text;
            }
            else
            {
                textBox1.Text = button7.Text;
                inputstatus = true;
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button8.Text;
            }
            else
            {
                textBox1.Text = button8.Text;
                inputstatus = true;
            }

        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button9.Text;
            }
            else
            {
                textBox1.Text = button9.Text;
                inputstatus = true;
            }

        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (inputstatus)
            {
                textBox1.Text += button10.Text;
            }
            else
            {
                textBox1.Text = button10.Text;
                inputstatus = true;
            }


        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length != 0)
            {
                num1 = System.Double.Parse(textBox1.Text);
                result();
                cal = "+";
            }

        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length != 0)
            {
                num1 = System.Double.Parse(textBox1.Text);
                result();
                cal = "-";
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length != 0)
            {
                num1 = System.Double.Parse(textBox1.Text);
                result();
                cal = "*";
            }

        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length != 0)
            {
                num1 = System.Double.Parse(textBox1.Text);
                result();
                cal = "/";
            }

        }
        private void button16_Click(object sender, EventArgs e)
        {

            result();
            cal = string.Empty;

        }
        private void button15_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
            num1 = 0;
            num2 = 0;
            cal = string.Empty;
        }

        private void result()
        {
            num2 = System.Double.Parse(textBox1.Text);
            switch (cal)
            {
                case "+":
                    num1 = num1 + num2;
                    break;
                case "-":
                    num1 = num1 - num2;
                    break;
                case "*":
                    num1 = num1 * num2;
                    break;
                case "/":
                    num1 = num1 / num2;
                    break;
            }
            textBox1.Text = num1.ToString();
            inputstatus = false;
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Copy();
        }

        private void pasteCtrlVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Paste();
        }

        private void cutCtrlXToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Cut();
        }
    }
}


MOD EDIT: When posting code...USE CODE TAGS!!!

Attached image(s)

  • Attached Image

This post has been edited by JackOfAllTrades: 30 December 2010 - 05:26 AM

Was This Post Helpful? 0

Page 1 of 1