Advertisement
Guest User

C# Rekenmachine

a guest
Dec 13th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace RekenmachineProject
  12. {
  13. public partial class Form1 : Form
  14. {
  15. //variabelen
  16. string input;
  17. string som1 = string.Empty; //Eerste input
  18. char inputTekens; //Input tekens
  19. string som2 = string.Empty; //Tweede input
  20. double result; //Result
  21. double numb1;
  22. double numb2;
  23.  
  24. //form
  25. public Form1()
  26. {
  27. InitializeComponent();
  28. }
  29.  
  30. //cijfer intoetsen
  31. private void allButton_Click(object sender, EventArgs e)
  32. {
  33. input += (sender as Button).Text;
  34. textBoxDisplay.Text = input;
  35. }
  36.  
  37. //plus, min, keer, gedeeld door intoetsen
  38. private void buttonPlus_Click(object sender, EventArgs e)
  39. {
  40. inputTekens = '+';
  41. som1 = input;
  42. input = string.Empty;
  43. }
  44.  
  45. private void buttonMin_Click(object sender, EventArgs e)
  46. {
  47. inputTekens = '-';
  48. som1 = input;
  49. input = string.Empty;
  50. }
  51.  
  52. private void buttonKeer_Click(object sender, EventArgs e)
  53. {
  54. inputTekens = '*';
  55. som1 = input;
  56. input = string.Empty;
  57. }
  58.  
  59. private void buttonDelen_Click(object sender, EventArgs e)
  60. {
  61. inputTekens = ':';
  62. som1 = input;
  63. input = string.Empty;
  64. }
  65.  
  66. //Oplossing
  67. private void buttonOplossing_Click(object sender, EventArgs e)
  68. {
  69. som2 = input;
  70. double.TryParse(som1, out numb1);
  71. double.TryParse(som2, out numb2);
  72.  
  73. if (inputTekens == '+')
  74. {
  75. result = numb1 + numb2;
  76. textBoxDisplay.Text = result.ToString();
  77. }
  78.  
  79. if (inputTekens == '-')
  80. {
  81. result = numb1 - numb2;
  82. textBoxDisplay.Text = result.ToString();
  83. }
  84.  
  85. if (inputTekens == '*')
  86. {
  87. result = numb1 * numb2;
  88. textBoxDisplay.Text = result.ToString();
  89. }
  90.  
  91. if (inputTekens == ':')
  92. {
  93. result = numb1 / numb2;
  94. textBoxDisplay.Text = result.ToString();
  95. }
  96. }
  97.  
  98. //reset knop
  99. private void buttonReset_Click(object sender, EventArgs e)
  100. {
  101. this.textBoxDisplay.Text = "";
  102. this.input = string.Empty;
  103. this.som1 = string.Empty;
  104. this.som2 = string.Empty;
  105. }
  106.  
  107. //exit knop
  108. private void buttonExit_Click(object sender, EventArgs e)
  109. {
  110. this.Close();
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement