kalkulator bin/oct/hex/dec w c#

0

Witam, poniżej kod kalkulatora, w którym niby wszystko jest ok, ale visual studio pokazuje mi 12 błędów, których treść jest niżej.
Proszę o pomoc, bo nie daję sobie rady.
Pozdrawiam.

Error 1 Expected class, delegate, enum, interface, or struct d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 60 17 kalkulator1
Error 2 Expected class, delegate, enum, interface, or struct d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 93 17 kalkulator1
Error 3 Expected class, delegate, enum, interface, or struct d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 125 17 kalkulator1
Error 4 Expected class, delegate, enum, interface, or struct d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 158 17 kalkulator1
Error 5 Expected class, delegate, enum, interface, or struct d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 160 34 kalkulator1
Error 6 Expected class, delegate, enum, interface, or struct d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 163 17 kalkulator1
Error 7 Expected class, delegate, enum, interface, or struct d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 165 34 kalkulator1
Error 11 The name 'binNaDec' does not exist in the current context d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 38 42 kalkulator1
Error 12 The name 'binNaHex' does not exist in the current context d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 39 42 kalkulator1
Error 10 The name 'binNaOct' does not exist in the current context d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 37 42 kalkulator1
Error 9 The name 'poprawnyBin' does not exist in the current context d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 31 21 kalkulator1
Error 8 Type or namespace definition, or end-of-file expected d:\visual studio 2013\Projects\kalkulator1\kalkulator1\Form1.cs 167 9 kalkulator1

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;
using System.Net.Mail; 
using System.Text.RegularExpressions; 

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

                private void button1_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (poprawnyBin(this.textBox1.Text))
                {
                    string input = this.textBox1.Text;
                    this.textBox2.Clear();
                    this.textBox3.Clear();
                    this.textBox4.Clear();
                    this.textBox2.Text = binNaOct(input);
                    this.textBox3.Text = binNaDec(input);
                    this.textBox4.Text = binNaHex(input);
                }
                else
                {
                    this.textBox1.Text = "Niepoprawne dane!";
                    return;
                }
			 }
            catch (OverflowException oEx)
            {
                this.textBox1.Clear();
                this.textBox1.Text = "Błąd!";
            }
            catch (FormatException fEx)
            {
                this.textBox1.Clear();
                this.textBox1.Text = "Błąd!";
            }
        }
                    }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                if (poprawnyOct(this.textBox5.Text))
                {
                    string input = this.textBox5.Text;
                    this.textBox8.Clear();
                    this.textBox7.Clear();
                    this.textBox6.Clear();
                    this.textBox8.Text = decNaBin(octNaDec(input));
                    this.textBox7.Text = octNaDec(input);
                    this.textBox6.Text = binNaHex(decNaBin(octNaDec(input)));
                }
                else
                {
                    this.textBox5.Text = "Niepoprawne dane!";
                    return;
                }
				catch (OverflowException oEx)
            {
                this.textBox5.Clear();
                this.textBox5.Text = "Błąd!";
            }
            catch (FormatException fEx)
            {
                this.textBox5.Clear();
                this.textBox5.Text = "Błąd!";
            }
				
            }
                   }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                if (poprawnyDec(this.textBox9.Text))
                {
                    string input = this.textBox9.Text;
                    this.textBox12.Clear();
                    this.textBox11.Clear();
                    this.textBox10.Clear();
                    this.textBox12.Text = decNaBin(input);
                    this.textBox11.Text = binNaOct(decNaBin(input));
                    this.textBox10.Text = binNaDec(decNaBin(input));
                }
                else
                {
                    this.textBox9.Text = "Niepoprawne dane!";
                    return;
                }
				catch (OverflowException oEx)
            {
                this.textBox9.Clear();
                this.textBox9.Text = "Błąd!";
            }
            catch (FormatException fEx)
            {
                this.textBox9.Clear();
                this.textBox9.Text = "Błąd";
            }
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                if (poprawnyHex(this.textBox13.Text))
                {
                    string input = this.textBox13.Text;
                    this.textBox16.Clear();
                    this.textBox15.Clear();
                    this.textBox14.Clear();
                    this.textBox16.Text = decNaBin(hexNaDec(input));
                    this.textBox15.Text = binNaOct(decNaBin(hexNaDec(input)));
                    this.textBox14.ext = hexNaDec(input);
                    return;
                }
                else
                {
                    this.textBox13.Text = "Niepoprawne dane!";
                    return;
                }
				catch (OverflowException oEx)
            {
                this.textBox13.Clear();
                this.textBox13.Text = "Błąd!";
            }
            catch(FormatException fEx)
            {
                this.textBox13.Clear();
                this.textBox13.Text = "Błąd!";
            }

                    }

        private bool poprawnyBin(string input)
        {
            Regex regExObj = new Regex("^[0-1]+$");
            return regExObj.IsMatch(input);
        }
        private bool poprawnyOct(string input)
        {
            Regex regExObj = new Regex("^[0-7]+$");
            return regExObj.IsMatch(input);
        }   
        private bool poprawnyDec(string input)
        {
            Regex regExObj = new Regex("^[0-9]+$");
            return regExObj.IsMatch(input);
        }   
        private bool poprawnyHex(string input)
        {
            Regex regExObj = new Regex("^[0-9a-fA-F]+$");
            return regExObj.IsMatch(input);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox1.Clear();
            this.textBox2.Clear();
            this.textBox3.Clear();
            this.textBox4.Clear();
            this.textbox5.Clear();
            this.textBox6.Clear();
            this.textBox7.Clear();
            this.textBox8.Clear();
            this.textBox9.Clear();
            this.textBox10.Clear();
            this.textBox11.Clear();
            this.textBox12.Clear();
            this.textBox13.Clear();
            this.textBox14.Clear();
            this.textBox15.Clear();
            this.textBox16.Clear();
         }  
        private string binNaOct(string wyrażenie)
        {
          
            string oct = "";
            string wynik = "";
            UInt64 length = Convert.ToUInt64(wyrażenie.Length);
            for (UInt64 i = 1; i <= length; i = i + 3)
            {
                if (wyrażenie.Length >= 3)
                {
                    for (int j = 1; j <= 3 && wyrażenie.Length >= 3; j++)
                    {
                        octal += wyrażenie[wyrażenie.Length - j];
                        if (j == 3)
                            wyrażenie = wyrażenie.Substring(0, wyrażenie.Length - 3);
                    }
                }
                else
                    oct = wyrażenie;
                wynik += binNaDec(odwracanie(oct));
                oct = "";
            }

            
            wynik = odwracanie(wynik);
            return wynik;
        }   

        private string binNaDec(string wyrażenie)
        {
            double liczba = 1;
            double wynik = 0;
            int licznik = 0;
            double bufor;
            for (int i = wyrażenie.Length - 1; i >= 0; i--)
            {
                liczba = Math.Pow(2.00, (double)i);
                bufor = (char)(wyrażenie[licznik++] - '0');
                bufor = bufor * liczba;
                wynik += bufor;
            }
            return wynik.ToString();
        }

        private string binNaHex(string wyrażenie)
        {
            string hex = "";
            string wynik = "";
            string bufor = "";
            UInt64 length = Convert.ToUInt64(wyrażenie.Length);
            for (UInt64 i = 1; i <= length; i = i + 4)
            {
                if (wyrażenie.Length >= 4)
                {
                    for (int j = 1; j <= 4 && wyrażenie.Length >= 4; j++)
                    {
                        hex += wyrażenie[wyrażenie.Length - j];
                        if (j == 4)
                            wyrażenie = wyrażenie.Substring(0, wyrażenie.Length - 4);
                    }
                }
                else
                    hex = odwracanie(wyrażenie);
                bufor = binNaDec(odwracanie(hex));
                switch (bufor)
                {
                    case "10":
                        wynik += "A";
                        break;
                    case "11":
                        wynik += "B";
                        break;
                    case "12":
                        wynik += "C";
                        break;
                    case "13":
                        wynik += "D";
                        break;
                    case "14":
                        wynik += "E";
                        break;
                    case "15":
                        wynik += "F";
                        break;
                    default:
                        wynik += bufor;
                        break;
                }
                hex = "";
            }

                        wynik = odwracanie(wynik);
            return wynik;
        }         

                private string decToBin(string wyrażenie)
        {
            UInt64 number = Convert.ToUInt64(wyrażenie);
            string wynik = "";
            while (number != 0)
            {
                wynik += (number % 2).ToString();
                number = number / 2;
            }
            return odwracanie(wynik);
        } 

         
        private string octNaDec(string wyrażenie)
        {
            UInt64 number = Convert.ToUInt64(wyrażenie);
            int length = wyrażenie.Length;
            double wynik = 0.0;
            double liczba = 0.0;
            double licznik = 0.0;
            for (int i = length - 1; i >= 0; i--)
            {
                liczba = Math.Pow(8.00, licznik);
                wynik += ((wyrażenie[i] - '0') * liczba);
                licznik++;
            }
            return wynik.ToString();
        }

        private string hexNaDec(string wyrażenie)
        {
            double wynik = 0;
            double liczba = 1.00;
            int licznik = 0;
            char bufor;
            UInt64 length = Convert.ToUInt64(wyrażenie.Length);
            for (UInt64 i = length; i > 0; i--)
            {
                liczba = System.Math.Pow(16.00, Convert.ToDouble(i-1));
                bufor = (char)wyrażenie[licznik];
                switch (bufor)
                {
                    case 'a':
                    case 'A':
                        wynik += 10 * liczba;
                        licznik++;
                        break;
                    case 'b':
                    case 'B':
                        wynik += 11 * liczba;
                        licznik++;
                        break;
                    case 'c':
                    case 'C':
                        wynik += 12 * liczba;
                        licznik++;
                        break;
                    case 'd':
                    case 'D':
                        wynik += 13 * liczba;
                        licznik++;
                        break;
                    case 'e':
                    case 'E':
                        wynik += 14 * liczba;
                        licznik++;
                        break;
                    case 'f':
                    case 'F':
                        wynik += 15 * liczba;
                        licznik++;
                        break;
                    default:
                        wynik += (wyrażenie[licznik] - '0') * liczba;
                        licznik++;
                        break;
                }
            }
            return Convert.ToString(wynik);
        } 
        private static string odwracanie( string wyrażenie )
        {
            string bufor = "";
            for ( int i = wyrażenie.Length - 1; i >= 0; i-- )
            {
                bufor += wyrażenie[i];
            }
            return bufor;
        }

      
    }


0

Oj tam podczas przekopiowywania coś źle na wklejałeś i Ci się klamerki poprzestawiały. Popraw sobie sam. :P

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