Kyaria icon

Perish all Demons!

Kyaria | PRO | 02/28/18 08:38:40 PM UTC | 0 ⭐ | 355 👁️ | Never ⏰ | []
C# |

4.99 KB

|

None

|

0 👍

/

0 👎

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 Ghettorechner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            textBox1.Enabled = false;
        }
 
        private void button7_Click(object sender, EventArgs e)
        {
            if (sender == button1) { textBox1.Text += "7"; } // 7
            else if (sender == button2) { textBox1.Text += "8"; } // 8
            else if (sender == button3) { textBox1.Text += "9"; } // 9
            else if (sender == button4) { textBox1.Text += "4"; } // 4
            else if (sender == button5) { textBox1.Text += "5"; } // 5
            else if (sender == button6) { textBox1.Text += "6"; } // 6
            else if (sender == button7) { textBox1.Text += "1"; } // 1
            else if (sender == button8) { textBox1.Text += "2"; } // 2
            else if (sender == button9) { textBox1.Text += "3"; } // 3
            else if (sender == button10) { textBox1.Text += "0"; } // 0
            else if (sender == button11) { textBox1.Text += "."; } // .
            else if (sender == button12) { textBox1.Clear(); } // AC
            else if (sender == button13) { textBox1.Text += "+"; } // +
            else if (sender == button14) { textBox1.Text += "*"; } // *
            else if (sender == button16) { textBox1.Text += "-"; } // -
            else if (sender == button17) { textBox1.Text += "/"; } // /
            else if (sender == button18) { textBox1.Text += "("; } // (
            else if (sender == button19) { textBox1.Text += ")"; } // )
        }
 
        private string calc_code(string calc_code_one)
        {
            double TheAnswer = sub_code(calc_code_one);
            return TheAnswer.ToString();
        }
 
        private void pressed_enter(object sender, EventArgs e) 
        {
            //textBox1.Text = calc_code(textBox1.Text);
            textBox1.Text = RemoveTheDemons(textBox1.Text);
        }
 
        private string RemoveTheDemons(string calc_code_one)
        {
            //string[] demons = calc_code.Split('(', ')');
 
            while (calc_code_one.Contains('(') && calc_code_one.Contains(')'))
            {
                int openindex = 0;
                int closedindex = 0;
 
                for (int i = 0; i < calc_code_one.Length; i++)
                {
                    if (calc_code_one[i] == '(')
                    {
                        openindex = i;
                    }
                    if (calc_code_one[i] == ')')
                    {
                        closedindex = i;
 
                        calc_code_one = calc_code_one.Remove(openindex, closedindex - openindex + 1).Insert(openindex, PerishTheDemons(openindex, closedindex, calc_code_one));
 
                        break;
                    }
                }
            }
 
            if (calc_code_one[0] == '-') // Kümmert sich um ein - am Anfang
            {
                calc_code_one = '0' + calc_code_one;
            }
 
            return calc_code(calc_code_one); ;
        }
 
        private string PerishTheDemons(int open, int close, string calc_code_one)
        {
            string DemonsAnswer = calc_code(calc_code_one.Substring(open + 1, close - open - 1));
 
            return DemonsAnswer;
        }
 
        private double sub_code(string calc_code_one)
        {
            string[] calc_array = calc_code_one.Split('-');
            double stage_one = add_code(calc_array[0]);
 
            for (int i = 1; i < calc_array.Length; i++)
            {
                stage_one = stage_one - add_code(calc_array[i]);
            }
 
            return stage_one;
        }
 
        private double add_code(string calc_code_one)
        {
            string[] calc_array = calc_code_one.Split('+');
            double stage_one = mult_code(calc_array[0]);
 
            for (int i = 1; i < calc_array.Length; i++)
            {
                stage_one = stage_one + mult_code(calc_array[i]);
            }
 
            return stage_one;
        }
 
        private double mult_code(string calc_code_one)
        {
            string[] calc_array = calc_code_one.Split('*');
            double stage_one = dev_code(calc_array[0]);
 
            for (int i = 1; i < calc_array.Length; i++)
            {
                stage_one = stage_one * dev_code(calc_array[i]);
            }
 
            return stage_one;
        }
 
        private double dev_code(string calc_code_one)
        {
            string[] calc_array = calc_code_one.Split('/');
            double stage_one = Convert.ToDouble(calc_array[0]);
 
            for (int i = 1; i < calc_array.Length; i++)
            {
                stage_one = stage_one / Convert.ToDouble(calc_array[i]);
            }
 
            return stage_one;
        }
    }
}

Comments