Hey

Can someone explain me how I can make a simple calculator, which can plus to numbers together..
And later make the program ask if user wants to multiply or divide..?

## All 8 Replies

Start a Windows form application.
Add 3 Textboxes. Call them Number1, Number2 and Result.
Add a Button, in the Click handler add the values of Number1 and Nuber2 and put the result in the Result Textbox.

This can also be done as a Console Application.
Do you currently program?
I'm just trying to clarify where this should start.

Hello,
I am also a New Learner of C#, The below code is a Calculator code, which should be under the Calculate Button. you should make a simple Form, That contain TextValue1, TextValue2, ComboBox (for +, -, *, /), TextResult and a Calculate Button for this .... Hope This Help....

``````private void btnCalculate_Click(object sender, EventArgs e)
{
bool flag;

// This will hold the First Value and the Second Value and the Result for Calculation
double Value1, Value2, Result;

// This is Verify If the User Enter Digit data, If not, the Error Alert
flag = double.TryParse(txtValue1.Text, out Value1);
if (flag == false)
{
MessageBox.Show("Only digit Value", "Input Error");
txtValue1.Focus();
return;
}
flag = double.TryParse(txtValue2.Text, out Value2);
if (flag == false)
{
MessageBox.Show("Only digit Value", "Input Error");
txtValue2.Focus();
return;
}

Result = 0; // At First the Result will be ZERO(0)

// This Check what the User want to do, +, -, /, *
switch(ComboBox1.Text)// name given to the ComboBox
{
case "+":
Result = Value1 + Value2;
break;
case "-":
Result = Value1 - Value2;
break;
case "*":
Result = Value1 * Value2;
break;
case "/":
Result = Value1 / Value2;
break;
}
// Final Result is Display in the Text Box
txtResult.Text = Result.ToString();
}``````

#jnmisa

Which form did you make yours in, console or windows form, because i am trying to make it in a console.. -.-

Console apps don't have forms.

By the way what did you mean with a ComboBox (for +, -, *, /), one box or four boxes..?

@TurkAlush
The ComboBox (for +, -, *, /)(One BOX) mean that Under ComboBox Items(collection) property , you will write what you want to Select-- Which Operation sign you want, So Under the ComboBox Items (Collection) property U will write the four sign that you want there.... I have attached a simple diagram view of how it could look...

Thanks alot..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.