C# 尝试将计算器文本框项转换为int和char(用于+;*等),或将它们与start分开
我在编写一个计算器时遇到了一个问题,它可以在文本框中显示一个均衡值,如C# 尝试将计算器文本框项转换为int和char(用于+;*等),或将它们与start分开,c#,textbox,calculator,C#,Textbox,Calculator,我在编写一个计算器时遇到了一个问题,它可以在文本框中显示一个均衡值,如 25*3(6-5)^2然后将它们放入不同的数组中,以破坏ofc的订单 在将它们放入文本框之前,我首先尝试将它们分开,因此我使用了以下代码: namespace CalculatorForDS { public partial class Form1 : Form { public int i=0, j=0, x; int[] a; int[] b;
25*3(6-5)^2
然后将它们放入不同的数组中,以破坏ofc的订单
在将它们放入文本框之前,我首先尝试将它们分开,因此我使用了以下代码:
namespace CalculatorForDS
{
public partial class Form1 : Form
{
public int i=0, j=0, x;
int[] a;
int[] b;
char[] c;
void Process()
{
a = new int[100];
b = new int[100];
c = new char[100];
}
public Form1()
{
InitializeComponent();
Process();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 1;
a[i] = a[i] * 10^j + 1;
j++;
x = a[i];
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "(";
c[i] = '(';
i++;
j = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 2;
a[i] = a[i] * 10^j + 2;
j++;
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 3;
a[i] = a[i] * 10^j + 3;
j++;
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 4;
a[i] = a[i] * 10^j + 4;
j++;
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 5;
a[i] = a[i] * 10^j + 5;
j++;
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 6;
a[i] = a[i] * 10^j + 6;
j++;
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 7;
a[i] = a[i] * 10^j + 7;
j++;
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 8;
a[i] = a[i] * 10^j + 8;
j++;
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 9;
a[i] = a[i] * 10^j + 9;
j++;
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ")";
c[i] = ')';
i++;
j = 0;
}
private void button18_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "^";
c[i] = '^';
i++;
j = 0;
}
private void button12_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "/";
c[i] = '/';
i++;
j = 0;
}
private void button19_Click(object sender, EventArgs e)
{
int lenght = textBox1.TextLength - 1;
string text = textBox1.Text;
textBox1.Clear();
for (int i = 0; i < lenght; i++)
textBox1.Text = textBox1.Text + text[i];
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "*";
c[i] = '*';
i++;
j = 0;
}
private void button14_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "-";
c[i] = '-';
i++;
j = 0;
}
private void button15_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "+";
c[i] = '+';
i++;
j = 0;
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + ".";
c[i] = '.';
i++;
j = 0;
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + 0;
a[i] = a[i] + j * 0;
j++;
}
private void button20_Click(object sender, EventArgs e)
{
listBox1.Items.Add(a[i]);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
名称空间计算器fords
{
公共部分类Form1:Form
{
公共整数i=0,j=0,x;
int[]a;
int[]b;
char[]c;
无效过程()
{
a=新整数[100];
b=新整数[100];
c=新字符[100];
}
公共表格1()
{
初始化组件();
过程();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+1;
a[i]=a[i]*10^j+1;
j++;
x=a[i];
}
私有无效按钮16_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+“(”;
c[i]='(';
i++;
j=0;
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
私有无效按钮2\u单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+2;
a[i]=a[i]*10^j+2;
j++;
}
私有无效按钮3\u单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+3;
a[i]=a[i]*10^j+3;
j++;
}
私有无效按钮4_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+4;
a[i]=a[i]*10^j+4;
j++;
}
私有无效按钮5_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+5;
a[i]=a[i]*10^j+5;
j++;
}
私有无效按钮6_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+6;
a[i]=a[i]*10^j+6;
j++;
}
私有无效按钮7_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+7;
a[i]=a[i]*10^j+7;
j++;
}
私有无效按钮8_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+8;
a[i]=a[i]*10^j+8;
j++;
}
私有无效按钮9_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+9;
a[i]=a[i]*10^j+9;
j++;
}
私有无效按钮17_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+”;
c[i]=')';
i++;
j=0;
}
私有无效按钮18_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+“^”;
c[i]='^';
i++;
j=0;
}
私有无效按钮12_单击(对象发送者,事件参数e)
{
textBox1.Text=textBox1.Text+“/”;
c[i]='/';
i++;
j=0;
}
私有无效按钮19_单击(对象发送者,事件参数e)
{
int lenght=textBox1.TextLength-1;
string text=textBox1.text;
textBox1.Clear();
对于(int i=0;i
但问题是,当我写例如:1和5时,它在文本框中显示15,但随后我使用列表框检查数组a[I]中的值,它给我12;或者115=84
我真的不知道怎么了
所以我想也许我可以用另一种方法,把它们放在一个文本框中,然后把文本框转换成int和char之类的数字和操作数
我的主要项目是使用堆栈,使用输入的textbox1均衡到后缀版本并显示它
虽然我知道C++,但在这个项目之前我不知道C,我想先尝试一些简单的代码,从Net中学习一些东西。
如果有人能帮助我,我会非常感激的我对我的程序做了一些修改,但最终还是出现了一些问题,比如 123 而不是像123号那样进入 1203 因此,我从一开始就重新编写了我的程序,并使用
String x;
char ch = x[i];
if ( ch == '+' || ch =='-' || ch =='*' || ch == '/' || ch == '^' )
{//Here comes the Operators, as for me it works for pushing operators into stack }
else
{//Here comes the Operands, as for me , it works for putting them in another String }
有了上面的代码,我可以在我的程序中做我想做的事情,也就是把中缀表达式变成后缀:D我对我的程序做了一些更改,但最后它仍然有pr