static void Main(string[] args) { Class1 c = new Class1(); int num1, num2, choice; SmartCalculator: Console.WriteLine("Give me a number so I can show you some magic"); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Another One.. Dj Khaled Voice"); num2 = Convert.ToInt32(Console.ReadLine()); Console.Clear(); Console.WriteLine("Do you want it done \n 1. Add \n 2.Subtract \n 3. Multiply \n 4.Divide"); choice = Convert.ToInt32(Console.ReadLine()); Console.Clear(); if (choice == 1) { c.Add(num1, num2); } else if (choice == 2) { c.Subtra(num1, num2); } else if (choice == 3) { c.Multi(num1, num2); } else if (choice == 4) { c.Divi(num1, num2); } else { Console.WriteLine("You messed up bruh"); } Console.ReadLine(); Console.Clear(); Console.WriteLine("Do you want to go again yes or no ?"); string opt = Console.ReadLine(); if (opt == "yes") { goto SmartCalculator; } else { Console.WriteLine("You'll be back....."); } Console.ReadKey(); Console.Clear(); }
private void button19_Click(object sender, EventArgs e) //点击求余号 { string lastmatch = ""; Regex reg = new Regex(@"[\+|×|\-|÷|%]"); MatchCollection matchs = reg.Matches(label2.Text); int matchcount = matchs.Count; if (matchcount > 0) { lastmatch = matchs[matchcount - 1].Value;//确定上一个运算符是什么 } if (label1.Text.Length > 0) { string nowstring = label1.Text; label2.Text += nowstring + "%"; } flag = 0; //修改标志值 if (lastmatch == "+") //当上一个运算符为加号时,先算出结果 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Add(b, a); label1.Text = result.ToString(); } if (lastmatch == "×") //当上一个运算符为乘号时,先算出结果 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Multi(b, a); label1.Text = result.ToString(); } if (lastmatch == "-") //当上一个运算符为减号时,先算出结果 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Sub(b, a); label1.Text = result.ToString(); } if (lastmatch == "÷") //当上一个运算符为除号时,先算出结果 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Divi(b, a); label1.Text = result.ToString(); } if (lastmatch == "%") //当上一个运算符为求余号时,先算出结果 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Surplus(b, a); label1.Text = result.ToString(); } lastnum = label1.Text; }
private void button10_Click(object sender, EventArgs e) //等号 { int label2_lenth = label2.Text.Length; if (label2.Text.Substring(label2_lenth - 1, 1) == "+") //调用dll实现加法 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Add(b, a); label1.Text = result.ToString(); label2.Text = ""; } else if (label2.Text.Substring(label2_lenth - 1, 1) == "-") //调用dll实现减法 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Sub(b, a); label1.Text = result.ToString(); label2.Text = ""; } else if (label2.Text.Substring(label2_lenth - 1, 1) == "×") //调用dll实现乘法 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Multi(b, a); label1.Text = result.ToString(); label2.Text = ""; } else if (label2.Text.Substring(label2_lenth - 1, 1) == "÷") //调用dll实现除法 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Divi(b, a); label1.Text = result.ToString(); label2.Text = ""; } else if (label2.Text.Substring(label2_lenth - 1, 1) == "%") //调用dll实现求余 { Class1 myadd = new Class1(); Double a = Convert.ToDouble(label1.Text); Double b = Convert.ToDouble(lastnum); Double result = myadd.Surplus(b, a); label1.Text = result.ToString(); label2.Text = ""; } flag = 0; string myresult = label1.Text; ss.Speak("等于"); ss.Speak(myresult); }