namespace Calcolatrice
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
double total1 = 0;
double total2 = 0;
bool plusButtonClicked = false;
bool minusButtonClicked = false;
bool divideButtonClicked = false;
bool multiplyButtonClicked = false;
private void btnOne_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnOne.Content;
}
private void btnTwo_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnTwo.Content;
}
private void btnThree_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnThree.Content;
}
private void btnFour_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnFour.Content;
}
private void btnFive_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnFive.Content;
}
private void btnSix_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSix.Content;
}
private void btnSeven_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSeven.Content;
}
private void btnNine_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnNine.Content;
}
private void btnEight_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnEight.Content;
}
private void btnZero_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnZero.Content;
}
private void btnClear_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = "";
}
private void btnPlus_Click(object sender, RoutedEventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Text ="";
plusButtonClicked = true;
minusButtonClicked = false;
divideButtonClicked = false;
multiplyButtonClicked = false;
}
private void btnEquals_Click(object sender, RoutedEventArgs e)
{
if (plusButtonClicked == true)
{
total2 = total1 + double.Parse(txtDisplay.Text);
}
else if (minusButtonClicked == true)
{
total2 = total1 - double.Parse(txtDisplay.Text);
}
else if (divideButtonClicked == true)
{
total2 = total1 / double.Parse(txtDisplay.Text);
}
else if (multiplyButtonClicked == true)
{
total2 = total1 * double.Parse(txtDisplay.Text);
}
txtDisplay.Text = total2.ToString();
total1 = 0;
}
private void btnPoint_Click(object sender, RoutedEventArgs e)
{
txtDisplay.Text = txtDisplay.Text + ".";
}
private void btnMinus_Click(object sender, RoutedEventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Text = "";
plusButtonClicked = false;
minusButtonClicked = true;
divideButtonClicked = false;
multiplyButtonClicked = false;
}
private void btnMultiply_Click(object sender, RoutedEventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Text = "";
plusButtonClicked = false;
minusButtonClicked = false;
divideButtonClicked = false;
multiplyButtonClicked = true;
}
private void btnDivide_Click(object sender, RoutedEventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Text = "";
plusButtonClicked = false;
minusButtonClicked = false;
divideButtonClicked = true;
multiplyButtonClicked = false;
}
}
}