0% found this document useful (0 votes)
6 views

Document 4

Uploaded by

cedieguevarra10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Document 4

Uploaded by

cedieguevarra10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Code:

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;

using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace BasicCalculatorReyes

public partial class FrmBasicCalculator : Form

public FrmBasicCalculator()

InitializeComponent();

private void FrmBasicCalculator_Load(object sender, EventArgs e)

string[] List = new string[]

"+", "-", "*", "/"

};
comboBox1.Items.AddRange(List);

private void btnCompute_Click(object sender, EventArgs e)

try

float num1 = float.Parse(textBox1.Text);

float num2 = float.Parse(textBox2.Text);

float result = 0;

string operation = comboBox1.SelectedItem.ToString();

if (operation == "+")

result = num1 + num2;

else if (operation == "-")

result = num1 - num2;

else if (operation == "*")

result = num1 * num2;

else if (operation == "/")

if (num2 != 0)

result = num1 / num2;


else

MessageBox.Show("Cannot divide by zero");

return;

else

MessageBox.Show("Please select a valid operation.");

return;

label3.Text = result.ToString();

catch (FormatException)

MessageBox.Show("Please enter valid numbers.");

catch (Exception ex)

MessageBox.Show($"An error occurred: {ex.Message}");

} }

using System;

using System.Collections.Generic;
using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace CalculatorPrivateAssemblyReyes

public class BasicComputation

public static float Add(float a, float b)

return a + b;

public static float Subtract(float a, float b)

return a - b;

public static float Multiply(float a, float b)

return a * b;

public static float Divide(float a, float b)

if (b == 0)

throw new DivideByZeroException("Cannot divide by zero");


return a / b;

RESULT:

You might also like