Requirements: Visual Studio 2015 or higher version with Windows SDK.

Step 1: Open Visual Studio 2015 and afterwards, go to File and go to New. Now, go to project.

File→New→Project.

Project

Step 2: We can choose Visual C# and select Windows. Afterwards, select the universal and next select the Blank App(Universal Windows).

Visual C#→Windows→universal→Blank App(Universal Windows).

Blank App

Step 3: Choose the target and minimum platform versions, which your Universal Windows Application will support.

application

Step 4: Open Mainpage.XAML, add the codes given below:

 platform versions

The page is given below:

design

Step 5: Open Mainpage.cs file, add the code, given below:

  1. namespace calculator12
  2. {
  3. /// <summary>
  4. /// An empty page that can be used on its own or navigated to within a Frame.
  5. /// </summary>
  6. public sealed partial class MainPage : Page
  7. {
  8. string input = string.Empty;
  9. string x = string.Empty;
  10. string y = string.Empty;
  11. char operation;
  12. double result = 0.0;
  13. public MainPage()
  14. {
  15. this.InitializeComponent();
  16. }
  17. private void button1_Click(object sender, RoutedEventArgs e)
  18. {
  19. this.textBox.Text = " ";
  20. input += "1";
  21. this.textBox.Text += input;
  22. }
  23. private void button_Click(object sender, RoutedEventArgs e)
  24. {
  25. this.textBox.Text = " ";
  26. input += "2";
  27. this.textBox.Text += input;
  28. }
  29. private void button2_Click(object sender, RoutedEventArgs e)
  30. {
  31. this.textBox.Text = " ";
  32. input += "3";
  33. this.textBox.Text += input;
  34. }
  35. private void button3_Click(object sender, RoutedEventArgs e)
  36. {
  37. this.textBox.Text = " ";
  38. input += "4";
  39. this.textBox.Text += input;
  40. }
  41. private void button4_Click(object sender, RoutedEventArgs e)
  42. {
  43. this.textBox.Text = " ";
  44. input += "5";
  45. this.textBox.Text += input;
  46. }
  47. private void button5_Click(object sender, RoutedEventArgs e)
  48. {
  49. this.textBox.Text = " ";
  50. input += "6";
  51. this.textBox.Text += input;
  52. }
  53. private void button6_Click(object sender, RoutedEventArgs e)
  54. {
  55. this.textBox.Text = " ";
  56. input += "7";
  57. this.textBox.Text += input;
  58. }
  59. private void button7_Click(object sender, RoutedEventArgs e)
  60. {
  61. this.textBox.Text = " ";
  62. input += "8";
  63. this.textBox.Text += input;
  64. }
  65. private void button8_Click(object sender, RoutedEventArgs e)
  66. {
  67. this.textBox.Text = " ";
  68. input += "9";
  69. this.textBox.Text += input;
  70. }
  71. private void button9_Click(object sender, RoutedEventArgs e)
  72. {
  73. this.textBox.Text = " ";
  74. input += "0";
  75. this.textBox.Text += input;
  76. }
  77. private void button10_Click(object sender, RoutedEventArgs e)
  78. {
  79. x = input;
  80. operation = '+';
  81. input = string.Empty;
  82. }
  83. private void button11_Click(object sender, RoutedEventArgs e)
  84. {
  85. x = input;
  86. operation = '-';
  87. input = string.Empty;
  88. }
  89. private void button12_Click(object sender, RoutedEventArgs e)
  90. {
  91. x = input;
  92. operation = '*';
  93. input = string.Empty;
  94. }
  95. private void button13_Click(object sender, RoutedEventArgs e)
  96. {
  97. x = input;
  98. operation = '/';
  99. input = string.Empty;
  100. }
  101. private void button14_Click(object sender, RoutedEventArgs e)
  102. {
  103. this.textBox.Text = " ";
  104. input += ".";
  105. this.textBox.Text += input;
  106. }
  107. private void button16_Click(object sender, RoutedEventArgs e)
  108. {
  109. y = input;
  110. double num1, num2;
  111. double.TryParse(x, out num1);
  112. double.TryParse(y, out num2);
  113. if (operation == '+')
  114. {
  115. result = num1 + num2;
  116. textBox.Text = result.ToString();
  117. }
  118. else if (operation == '-')
  119. {
  120. result = num1 - num2;
  121. textBox.Text = result.ToString();
  122. }
  123. else if (operation == '*')
  124. {
  125. result = num1 * num2;
  126. textBox.Text = result.ToString();
  127. }
  128. else if (operation == '/')
  129. {
  130. if (num2 != 0)
  131. {
  132. result = num1 / num2;
  133. textBox.Text = result.ToString();
  134. }
  135. else
  136. {
  137. textBox.Text = "DIV/Zero!";
  138. }
  139. }
  140. }
  141. private void button15_Click(object sender, RoutedEventArgs e)
  142. {
  143. textBox.Text = "0";
  144. }
  145. }
  146. }
design

design

design

design

design

design

design

Step 6: You can run the project.

output

Step 7: You can see the output, given below:

output

output