Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace FirstWFAapp
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnChange_Click(object sender, EventArgs e)
- {
- Button button = (Button)sender;
- int a, b;
- double result = 0;
- bool isResult = true;
- try
- {
- a = int.Parse(tbName.Text);
- b = int.Parse(tbSurname.Text);
- }
- catch {
- MessageBox.Show("Please enter numbers!");
- tbName.Text = tbSurname.Text = "";
- return;
- }
- switch (button.Text)
- {
- case "+":
- result = a + b;
- break;
- case "-":
- result = a - b;
- break;
- case "*":
- result = a * b;
- break;
- case "/":
- if (b != 0)
- result = (double)a / b;
- else
- {
- lblScreen.Text = "Don't devide by 0!";
- isResult = false;
- }
- break;
- default:
- break;
- }
- if (isResult)
- lblScreen.Text = $"{a} {button.Text} {b} = {result}";
- //tbName.Text = "";
- //tbSurname.Text = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement