Created
June 16, 2017 21:40
-
-
Save mayleone1994/7591a1b9a87035565059e57920efd157 to your computer and use it in GitHub Desktop.
calculadora simples em c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 WindowsFormsApplication1 | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
} | |
public class Global | |
{ | |
public static string texto1 = " ", texto2 = " "; | |
public static int var1 = 0, var2 = 0, op = 0, entrada = 0; | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "7"; | |
} | |
else | |
{ | |
Global.texto2 += "7"; | |
} | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "8"; | |
} | |
else | |
{ | |
Global.texto2 += "8"; | |
} | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "9"; | |
} | |
else | |
{ | |
Global.texto2 += "9"; | |
} | |
} | |
private void button4_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "4"; | |
} | |
else | |
{ | |
Global.texto2 += "4"; | |
} | |
} | |
private void button5_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "5"; | |
} | |
else | |
{ | |
Global.texto2 += "5"; | |
} | |
} | |
private void button6_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "6"; | |
} | |
else | |
{ | |
Global.texto2 += "6"; | |
} | |
} | |
private void button7_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "1"; | |
} | |
else | |
{ | |
Global.texto2 += "1"; | |
} | |
} | |
private void button8_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "2"; | |
} | |
else | |
{ | |
Global.texto2 += "2"; | |
} | |
} | |
private void button9_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "3"; | |
} | |
else | |
{ | |
Global.texto2 += "3"; | |
} | |
} | |
private void button10_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.texto1 += "0"; | |
} | |
else | |
{ | |
Global.texto2 += "0"; | |
} | |
} | |
private void button12_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.entrada = 1; | |
Global.op = 1; | |
} | |
} | |
private void button13_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.entrada = 1; | |
Global.op = 2; | |
} | |
} | |
private void button14_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.entrada = 1; | |
Global.op = 3; | |
} | |
} | |
private void button15_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada == 0) | |
{ | |
Global.entrada = 1; | |
Global.op = 4; | |
} | |
} | |
private void button11_Click(object sender, EventArgs e) | |
{ | |
if (Global.entrada >= 1) | |
{ | |
Global.var1 = Convert.ToInt32(Global.texto1); | |
Global.var2 = Convert.ToInt32(Global.texto2); | |
for (int contador = 1; contador <=2; contador ++){ | |
switch (Global.op) | |
{ | |
case 1: | |
MessageBox.Show(Convert.ToString(Global.var1 + "+" + Global.var2 + "=" + (Global.var1 + Global.var2))); | |
Global.op = 5; | |
break; | |
case 2: | |
MessageBox.Show(Convert.ToString(Global.var1 + "-" + Global.var2 + "=" + (Global.var1 - Global.var2))); | |
Global.op = 5; | |
break; | |
case 3: | |
MessageBox.Show(Convert.ToString(Global.var1 + "x" + Global.var2 + "=" + (Global.var1 * Global.var2))); | |
Global.op = 5; | |
break; | |
case 4: | |
MessageBox.Show(Convert.ToString(Global.var1 + "/" + Global.var2 + "=" + (Global.var1 / Global.var2))); | |
Global.op = 5; | |
break; | |
case 5: | |
Global.texto1 = " "; | |
Global.texto2 = " "; | |
Global.var1 = 0; | |
Global.var2 = 0; | |
Global.entrada = 0; | |
Global.op = 0; | |
break; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment