string last = ""; bool minus = false; bool plus = false; bool divide = false; bool multiply = false; string memory = ""; public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { if (textBox1.Text.Contains(",")) { return;
C#(Sharp): I made my code and design below. Anybody can help me some correction and add some design button and code. "Need to make C# step by step design and code "Calculator where make a calculator program that can do add, subtract, multiply, divide and square root. It should have a memory save/restore function for one number. There should be a way to set the number of fraction digits displayed".
-
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;
namespace AktCalc
{
public partial class Form1 : Form
{
string last = "";
bool minus = false;
bool plus = false;
bool divide = false;
bool multiply = false;
string memory = "";
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
-
if (textBox1.Text.Contains(","))
{
return;
}
else
{
textBox1.Text += ",";
}
}
private void button21_Click(object sender, EventArgs e)
{
last = textBox1.Text;
multiply = true;
}
private void button3_Click(object sender, EventArgs e)
{
last = textBox1.Text;
plus = true;
}
private void button5_Click(object sender, EventArgs e)
{
last = textBox1.Text;
divide = true;
}
-
private void button4_Click(object sender, EventArgs e)
{
last = textBox1.Text;
minus = true;
}
// Equalls =
private void button6_Click(object sender, EventArgs e)
{
if (minus)
{
decimal equals1;
equals1 = Convert.ToDecimal(last) - Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(equals1);
}
if (plus)
{
decimal equals1;
equals1 = Convert.ToDecimal(last) + Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(equals1);
}
if (divide)
{
decimal equals1;
-
equals1 = Convert.ToDecimal(last) / Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(equals1);
}
if (multiply)
{
decimal equals1;
equals1 = Convert.ToDecimal(last) * Convert.ToDecimal(textBox1.Text);
textBox1.Text = Convert.ToString(equals1);
}
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = Convert.ToString(Math.Sqrt(Convert.ToDouble(textBox1.Text)));
}
private void button1_Click(object sender, EventArgs e)
{
memory = textBox1.Text;
label1.Text = "M";
}
private void button10_Click(object sender, EventArgs e)
{
memory = "";
label1.Text = "";
}
-
private void button15_Click(object sender, EventArgs e)
{
textBox1.Text = memory;
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.Text = "";
multiply = false;
plus = false;
minus = false;
divide = false;
}
private void button20_Click(object sender, EventArgs e)
{
textBox1.Text += "0";
}
private void button19_Click(object sender, EventArgs e)
{
textBox1.Text += "1";
}
private void button18_Click(object sender, EventArgs e)
{
-
textBox1.Text += "2";
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.Text += "3";
}
private void button14_Click(object sender, EventArgs e)
{
textBox1.Text += "4";
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text += "5";
}
private void button12_Click(object sender, EventArgs e)
{
textBox1.Text += "6";
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += "7";
}
-
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text += "8";
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images