Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void button2_Click(object sender, EventArgs e)
- {
- Vreme.Stop();
- if (textBox1.Text == "")
- {
- MessageBox.Show("Niste uneli resenje!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- string temp = textBox1.Text;
- string output = temp.Substring(temp.Length - 1, 1);
- /*if(!(textBox1.Text.Contains(button3.Text)|| textBox1.Text.Contains(button4.Text)|| textBox1.Text.Contains(button5.Text)|| textBox1.Text.Contains(button6.Text)|| textBox1.Text.Contains(button7.Text)|| textBox1.Text.Contains(button8.Text)))
- {
- MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }*/
- if(textBox1.Text.StartsWith("+")|| textBox1.Text.StartsWith("-")|| textBox1.Text.StartsWith("*")|| textBox1.Text.StartsWith("/"))
- {
- MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (output == button3.Text)
- {
- MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (output == button4.Text)
- {
- MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (output == button5.Text)
- {
- MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (output == button6.Text)
- {
- MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- var count = textBox1.Text.Count(x => x == '(');
- var count2 = textBox1.Text.Count(x => x == ')');
- if (count > count2 || count < count2)
- {
- MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- Parser par = new Parser();
- string line = textBox1.Text;
- char[] exp = line.ToCharArray();
- int value = par.EvaluateExpression(exp);
- textBox1.Text = value + "=" + line;
- Resavac re = new Resavac();
- int target;
- int target10;
- int target100;
- int hint1;
- int hint2;
- int hint3;
- int hint4;
- int hint5;
- int hint6;
- tbAnswer.Text = "";
- if (!int.TryParse(label2.Text, out target))
- {
- // tbTarget.Focus();
- return;
- }
- if (!int.TryParse(label3.Text, out target10))
- {
- //tbTarget.Focus();
- return;
- }
- if (!int.TryParse(label4.Text, out target100))
- {
- //tbTarget.Focus();
- return;
- }
- if (!int.TryParse(tbHint1.Text, out hint1))
- {
- tbHint1.Focus();
- return;
- }
- if (!int.TryParse(tbHint2.Text, out hint2))
- {
- tbHint2.Focus();
- return;
- }
- if (!int.TryParse(tbHint3.Text, out hint3))
- {
- tbHint3.Focus();
- return;
- }
- if (!int.TryParse(tbHint4.Text, out hint4))
- {
- tbHint4.Focus();
- return;
- }
- if (!int.TryParse(tbHint5.Text, out hint5))
- {
- tbHint5.Focus();
- return;
- }
- if (!int.TryParse(tbHint6.Text, out hint6))
- {
- tbHint6.Focus();
- return;
- }
- tbAnswer.Text = re.Calculate(target, target10, target100, hint1, hint2, hint3, hint4, hint5, hint6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement