Computer Hope

Software => Computer programming => Topic started by: dave_trodeau2000 on November 07, 2010, 01:42:29 AM

Title: How to add a multiply & division buttons in the program code???
Post by: dave_trodeau2000 on November 07, 2010, 01:42:29 AM


Sir I runned this program already but without the multiply & division buttons in the program code.And please help me sir!!

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 calculator2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void txtDisplay_TextChanged(object sender, EventArgs e)
        {
        }
        double total1 = 0;
        double total2 = 0;
        double answer;

        private void btnOne_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnOne.Text;
        }
        private void btnTwo_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
        }
        private void btnThree_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnThree.Text;
        }
        private void btnFour_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnFour.Text;
        }
        private void btnFive_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnFive.Text;
        }
        private void btnSix_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnSix.Text;
        }
        private void btnSeven_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnSeven.Text;
        }
        private void btnEight_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnEight.Text;
        }
        private void btnNine_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnNine.Text;
        }
        private void btnZero_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnZero.Text;
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            txtDisplay.Clear();
        }
        private void btnPlus_Click(object sender, EventArgs e)
        {
            total1 = total1 + double.Parse(txtDisplay.Text);
            txtDisplay.Clear();

            plusButtonClicked = true;
            minusButtonClicked = false;
            divideButtonClicked = false;
            multiplyButtonClicked = false;
        }
        private void btnEquals_Click(object sender, EventArgs e)
        {
            if (plusButtonClicked == true)
               
            {
                total2 = total1 + double.Parse(txtDisplay.Text);
               
            }
            if (multiplyButtonClicked == true)
            {
                total2 = total1 * double.Parse(txtDisplay.Text);
            }
            else if (minusButtonClicked == true)
            {
                total2 = total1 - double.Parse(txtDisplay.Text);

            }
            else if (divideButtonClicked == true)
            {
                total2 = total1 / double.Parse(txtDisplay.Text);
            }
            txtDisplay.Text = total2.ToString();
            total1 = 0;
        }
        private void btnPoint_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnPoint.Text;
        }
        bool plusButtonClicked = false;
        bool minusButtonClicked = false;
        bool divideButtonClicked = false;
        bool multiplyButtonClicked = false;
        private void btnMinus_Click(object sender, EventArgs e)
        {
            total1 = total1 + double.Parse(txtDisplay.Text);
            txtDisplay.Clear();

            minusButtonClicked = true;
            plusButtonClicked = false;
            divideButtonClicked = false;
            multiplyButtonClicked = false;
        }
       
        private void btnMultiply_Click(object sender, EventArgs e)
        {
            total1 = total1 / double.Parse(txtDisplay.Text);
            multiplyButtonClicked = true;
            divideButtonClicked = true;
            minusButtonClicked = false;
            plusButtonClicked = false;
            txtDisplay.Clear();
        }

        private void btnDivide_Click(object sender, EventArgs e)
        {
            total1 = total1 / double.Parse(txtDisplay.Text);
            multiplyButtonClicked = true;
            divideButtonClicked = true;
            minusButtonClicked = false;
            plusButtonClicked = false;
            txtDisplay.Clear();
           
        }
    }
}
Title: Sir so this is correct format to send my posts here??
Post by: dave_trodeau2000 on November 10, 2010, 10:45:34 PM
Sir please reply me now if my posts here is correct.And please post me a message or example of correct format of code that can be post here.
Because I can`t move on in my program code in C sharp because of some errors I did recently here.
Title: Sir did you delete my duplicated posts here???
Post by: dave_trodeau2000 on November 12, 2010, 12:19:47 AM
Okay, If you are the one by deleting my duplicated posts here.That`s good.And I`m very thankful for that sir!! And how it is sir that until now I don`t have received a answer for the question I posted here?? :-\
Title: Re: Sir did you delete my duplicated posts here???
Post by: Salmon Trout on November 12, 2010, 06:57:39 AM
And how it is sir that until now I don`t have received a answer for the question I posted here?? :-\

You asked this question before, and received a very pertinent answer.
Title: Sir so can I please you again to delete my duplicated posts??
Post by: dave_trodeau2000 on November 13, 2010, 01:54:52 AM
Because I`m really don`t know how to delete my duplicated posts here!! :)
Title: Re: How to add a multiply & division buttons in the program code???
Post by: Salmon Trout on November 13, 2010, 02:01:39 AM
I meant, you asked, before, "How is it that until now I haven't received an answer?". You asked this

Quote
Sir I am waiting from then that my asked question in the date of Oct.04,2010, 4:26A.M.About my C# questions.And hoping to be answered.So now it is no replied messages in my inbox.So how it is Sir like that??and hoping to you sir more power!!

The answer is "because nobody posted an answer". There is no guarantee that every question will be answered, and it is foolish to complain if you do not get one. In fact, doing this may make people who know how to help you decide not to post.

Title: So are they members too like me that posting a questions here??
Post by: dave_trodeau2000 on November 13, 2010, 08:16:32 AM
Sir I`m very thankful for that answer.It`s because I`m really don`t know who is answering my questions here and I think there are working in this site and paid it to assigned for answering a questions here about software programming.
                And sir can you help me to delete my question here that is my program code in c sharp and a question in above of that code.Because that questions I asked there is very unclear and lack of grammar to be understand by the members here. ::)
Title: Re: So are they members too like me that posting a questions here??
Post by: Salmon Trout on November 13, 2010, 08:22:03 AM
Sir thank you for this answer.It`s because I`m really don`t know who is answering my questions here and I think there are working in this site and paid it to assigned for answering a questions here about software programming. :)

Nobody is paid here, any answers you might get are from other members like yourself, who may or may not know the answers you need, and are free to answer or not. If people were paid, where did you think the money comes from? Did you pay any money to join or ask questions?
Title: Ah okay sir thank you for that again!!
Post by: dave_trodeau2000 on November 13, 2010, 08:40:09 AM
Because I`m really new or I am a beginner to asked a questions in forum like this and I have no other forums like this that are the answer is right away or in the same day..And I feel comfortable for this site.. :)
Title: Re: So are they members too like me that posting a questions here??
Post by: BC_Programmer on November 13, 2010, 08:55:14 PM
Because that questions I asked there is very unclear and lack of grammar to be understand by the members here. ::)

That's somewhat true, but I understood enough to know exactly what the problem was, I believe. Your code contains both of the routines that  you say you don't have. So I think it follows from that that you have both the button and the code but you cannot "link" them together; that is, you've messed about with them enough that the event has gotten decoupled from the UI element. (this usually happens when you change the name of the procedure).

I also know that if you had read the Programmers guide at all, especially regarding the help for the Visual Studio UI, you would know exactly what do do. You can either use the Properties window to quickly re-link the events back together with their functions or you could even do something really crazy like double-click on the relevant buttons, at which point new Click Event procedures are generated, and use Copy-Paste to move the code from the old decoupled procedure to the new one.

The former is quite a lot easier.

This is one thing that I personally find rather annoying. nowadays, having a firm grasp of a programming language isn't enough to develop applications in the long-term, since nowadays we have to work with designers. One should make an effort to learn the User-interface and conventions of said environment for the creation of your UI elements, and "connecting" those UI elements with the appropriate code. To be clear, it's not annoying that people that are first learning it have trouble with problems that require UI elements tof the environment that are right in front of their face, it's when people post a question on the forum about it and seemingly stop trying to solve the problem themselves. It's been almost a week since you posted this. You would expect maybe a glance or two at the Visual Studio Programmers guide; specifically, the information on the Properties (http://msdn.microsoft.com/en-us/library/ms171352%28v=VS.90%29.aspx) window.

That was why I didn't answer. Both the solution as well as how to find it are neither obscure nor difficult to discover. It's a lack of initiative to blame here, a tendency to "oh, I hit a roadblock- I give up" and then post on a forum, wait a week, and essentially complain that nobody responded.

Title: Ah I see!!!
Post by: dave_trodeau2000 on November 13, 2010, 10:54:01 PM
But sir there are no definite answer if there are really experienced to solve any problems about programs in c sharp in this forum,am I right???And maybe myself only or my friend programmer could answer my questions someday about my calcultator program?? :-\
Title: Re: Ah I see!!!
Post by: BC_Programmer on November 13, 2010, 11:01:16 PM
And maybe myself only or my friend programmer could answer my questions someday about my calcultator program?? :-\
I just gave you two answers to your problem.
Title: Ah thank you sir,that you said it already to me!!
Post by: dave_trodeau2000 on November 14, 2010, 03:18:22 AM
And sir I have a duplicated posts again here.So can I please you sir to delete that again.Please!!! :)
Title: Don't edit the subject line each time you post a reply
Post by: Salmon Trout on November 14, 2010, 04:08:52 AM
Please!
Title: Ah okay sir thank you for that again!!
Post by: dave_trodeau2000 on November 14, 2010, 10:15:05 PM
thank you3x sir!!!