Wątek przeniesiony 2016-11-04 02:56 z C# i .NET przez somekind.

Visual studio 2015-problem z kodem?

0

Mam problem taki ze podczas wciśnięcia 8 wpisuje mi się 2 i wciśnięcia 2 wpisuje mi sie 8 ktos cos (jestem początkujący)

kod

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

namespace kalkulator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string LiczbaPierwsza, LiczbaDruga;
        char RodzajDziałania = ' ';
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Dzialanie(3);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Dzialanie(8);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Dzialanie(5);
        }

        private void bDodwanie_Click(object sender, EventArgs e)
        {
            RodzajDziałania = '+';
            tbWynik.Text = "";
        }

        private void bOdejmowanie_Click(object sender, EventArgs e)
        {
            RodzajDziałania = '-';
            tbWynik.Text = "";
        }

        private void bMnozenie_Click(object sender, EventArgs e)
        {
            RodzajDziałania = '*';
            tbWynik.Text = "";
        }

        private void bDzielenie_Click(object sender, EventArgs e)
        {
            RodzajDziałania = '/';
            tbWynik.Text = "";
        }

        private void b9_Click(object sender, EventArgs e)
        {
            Dzialanie(9);
        }

        private void b6_Click(object sender, EventArgs e)
        {
            Dzialanie(6);
        }

        private void b3_Click(object sender, EventArgs e)
        {
            Dzialanie(3);
        }

        private void bWynik_Click(object sender, EventArgs e)
        {
            switch(RodzajDziałania)
            {
                case ('+'):
                    tbWynik.Text = (int.Parse(LiczbaPierwsza) + int.Parse(LiczbaDruga)).ToString();
                    break;
                case ('-'):
                    tbWynik.Text = (int.Parse(LiczbaPierwsza) - int.Parse(LiczbaDruga)).ToString();
                    break;
                case ('*'):
                    tbWynik.Text = (int.Parse(LiczbaPierwsza) - int.Parse(LiczbaDruga)).ToString();
                    break;
                case('/'):
                    tbWynik.Text = (int.Parse(LiczbaPierwsza) - int.Parse(LiczbaDruga)).ToString();
                    break;
            }
        }

        private void b7_Click(object sender, EventArgs e)
        {
            Dzialanie(7);
        }

        private void b4_Click(object sender, EventArgs e)
        {
            Dzialanie(4);
        }

        private void b1_Click(object sender, EventArgs e)
        {
            Dzialanie(1);
        }

        private void b0_Click(object sender, EventArgs e)
        {
            Dzialanie(0);
        }
        private void b2_Click(object sender, EventArgs e)
        {
            Dzialanie(2);
        }
        private void Dzialanie(int liczba)
        {
            if (RodzajDziałania == ' ')
            {
                LiczbaPierwsza += liczba;
                tbWynik.Text = LiczbaPierwsza;
            }
            else
            {
                LiczbaDruga += liczba;
                tbWynik.Text = LiczbaDruga;            
            }
        }
    }
}
0

Pewnie masz pomylone napisy na przyciskach i wywołujesz metodę z 8 pod 2 i na odwrót. (w zamieszczonym kodzie nie ma informacji o tym co masz na przyciskach).

0

Dzieki faktycznie w tych 2 sie nie ustawiło pozdrawiam ;)

0

No i problem z głowy ;).

1 użytkowników online, w tym zalogowanych: 0, gości: 1