4 Replies - 611 Views - Last Post: 30 September 2015 - 05:04 PM Rate Topic: -----

#1 tuffluck  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 15

having problem with this calculator assign, done the coding, but...

Posted 29 September 2015 - 05:18 PM

I have this calculator assign. building was ok, no errors found and all the formulas are ok as well as the coding but I can't somehow make the desired buttons to display as outputs? Please help, thanks, Here's the code:

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 WindowsFormsApplication1
{
    public partial class ZardCalculaTrial : Form
    {

        double num1 = 0;
        double num2 = 0;
        char operand;
        double result = 0;

        public ZardCalculaTrial()
        {
            InitializeComponent();
        }

        private void b1_Click(object sender, EventArgs e)
        {
            output.Text += "1";
        }

        private void b2_Click(object sender, EventArgs e)
        {
            output.Text += "2";
        }

        private void b3_Click(object sender, EventArgs e)
        {
            output.Text += "3";
        }

        private void b4_Click(object sender, EventArgs e)
        {
            output.Text += "4";
        }

        private void b5_Click(object sender, EventArgs e)
        {
            output.Text += "5";
        }

        private void b6_Click(object sender, EventArgs e)
        {
            output.Text += "6";
        }

        private void b7_Click(object sender, EventArgs e)
        {
            output.Text += "7";
        }

        private void b8_Click(object sender, EventArgs e)
        {
            output.Text += "8";
        }

        private void b9_Click(object sender, EventArgs e)
        {
            output.Text += "9";
        }

        private void b0_Click(object sender, EventArgs e)
        {
            output.Text += "0";
        }

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

        private void bplus_Click(object sender, EventArgs e)
        {
            num1 = Convert.ToDouble(output.Text);

            operand = '+';
            output.Text = string.Empty;

        }

        private void bminus_Click(object sender, EventArgs e)
        {
            num1 = Convert.ToDouble(output.Text);
            operand = '-';
            output.Text = string.Empty;
        }

        private void btimes_Click(object sender, EventArgs e)
        {
            num1 = Convert.ToDouble(output.Text);
            operand = '*';
            output.Text = string.Empty;
        }

        private void bdivide_Click(object sender, EventArgs e)
        {
            num1 = Convert.ToDouble(output.Text);
            operand = '/';
            output.Text = string.Empty;
        }

        private void bequal_Click(object sender, EventArgs e)
        {
            try
            {

                num2 = Convert.ToDouble(output.Text);
                switch (operand)
                {
                    case '+': //kani i add
                        result = (num1 + num2);
                        break;


                    case '-': //i bawas
                        result = (num1 - num2);
                        break;

                    case '*': //kage bushin
                        result = (num1 * num2);
                        break;

                    case '/': //i hati
                        if (num2 != 0)
                        {
                            result = (num1 / num2);
                        }
                        else
                        {
                            output.Text = "Dili ma-divide og 0";
                        }
                        break;
                }
                output.Text = result.ToString();
            }

            catch (Exception ex)
            {
                MessageBox.Show("Oppps naa mali. Details: " +
                    ex.Message);
            }
        }


        private void bdot_Click(object sender, EventArgs e)
        {
            if (output.Text.Contains("."))
            {
                return;
            }

            output.Text += ".";


        }

        private void bsign_Click(object sender, EventArgs e)
        {
            double opera1;
            if (double.TryParse(output.Text, out opera1))
            {
                output.Text = (-opera1).ToString();
            }

        }

        private void brecipro_Click(object sender, EventArgs e)
        {
            double opera1;
            if (double.TryParse(output.Text, out opera1))
            {
                output.Text = (1 / opera1).ToString();
            }
        }


    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: having problem with this calculator assign, done the coding, but...

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5895
  • View blog
  • Posts: 20,130
  • Joined: 05-May 12

Re: having problem with this calculator assign, done the coding, but...

Posted 29 September 2015 - 05:53 PM

Ano ang nangyari?

Tell us what happened? What buttons are you pressing? What behavior are you seeing?

Sigurado ka na may output control na anak ng Form?

Are you sure that the Form has a child output control? Is the control visible?
Was This Post Helpful? 0
  • +
  • -

#3 tuffluck  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 15

Re: having problem with this calculator assign, done the coding, but...

Posted 29 September 2015 - 07:19 PM

May output po cya complete with the textbox and buttons, kaso lang, when I press the buttons, di po cya nag a-appear sa output textbox, ok naman po yung addressing ko sa kanila, I dunno, baka may kulang akong form o user control?

Thanks po

This post has been edited by Skydiver: 29 September 2015 - 07:28 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5895
  • View blog
  • Posts: 20,130
  • Joined: 05-May 12

Re: having problem with this calculator assign, done the coding, but...

Posted 29 September 2015 - 07:32 PM

For the English only readers on this forum (which is the majority), the translation of post #3 is:

View Posttuffluck, on 29 September 2015 - 10:19 PM, said:

There is output complete with the textbox and buttons, but when I press the buttons, nothing appears in the output textbox. My addressing of the [controls] seem to be okay, but I don't know if I'm missing a form or user control.


My first guess is that you failed to hookup the click event for each of your buttons. Try setting breakpoints on your event handlers and the press a button. If your breakpoints are not hit, you definitely forgot to set up the events.
Was This Post Helpful? 1
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,373
  • Joined: 02-June 10

Re: having problem with this calculator assign, done the coding, but...

Posted 30 September 2015 - 05:04 PM

I'd like to point out this is an English site. Even the FAQ for the site says to post in English.
http://www.dreaminco...announcement=22
We have a hard enough time with people posting in bad English and SMS/LEET-SPEAK without promoting the use of foreign languages.
The original question was in English. I don't know why you felt it a good idea to respond using a foreign language but by post #3 the thread has deteriorated into gibberish for the rest of the membership who can now no longer gain any value from the thread because of it.

To put it more bluntly:
Spoiler


This looks like a very straight-forward debugging situation.


tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.
Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute, check the condition of each of variable's run-time value, and watch the logic unfold right before your eyes.
Visualizing what your code does will let you see why it behaves the way it does.
It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.

In addition to FAQ 2 in the list below, also check my signature block for a link on how to look at your variables' values at run-time.

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2

Why are you still building in WinForms?

Quote

"old 1990's WinForms"? i just use visual studio 2015 and started up with a windows form. didn't know there was an option for a newer winform?


WinForms is OLD. Virtually 'legacy' and to many of us nearly considered end-of-life. There are still placing building new projects in it, but I wouldn't work for anyplace that wanted to hold me back by two decades. There are probably tens of thousands of legacy WinForms applications in use in countless companies. "If it ain't broke, don't fix it." in other words: If there isn't a financial gain to be made in re-writing them right now why invest the time and money?

But with decades of WinForms comes developers with decades more experience than you'll have and you have no way to compete with them. Let the legacy developer maintain the legacy applications. Many of them are too stuck in their ways to move forward to WPF. Which is why if you look at job boards, what companies are hiring for and have been looking for, for the last several years its: WPF/MVVM.

So if I were you I would just jump right to WPF. Don't worry about WinForms unless you have a deliberate need for it down the line. Otherwise you spend 10,000 hours getting good at WinForms only to find you need to spend another 7,500 hours bringing your skillset forward several years into WPF - And at the same time break all the bad habits you learned in WinForms.

If some company hires you for WPF development, but would also like it if you could maintain some legacy applications THEN learn WinForms; and take your good habits from WPF with you.


FAQ (Frequently Asked Questions - Updated Sep 2015
Spoiler



This post has been edited by tlhIn`toq: 30 September 2015 - 05:11 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1