Question

C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to...

C# Windows Form Application (CALCULATOR):

(This is the instruction below):

Windows Calculator that will going to create a Windows Form Application that will mimics a calculator. This is the screenshot how it shouldl look like. Calculator It should have a textbox and the following buttons: + Addition - Subtraction * Multiplication / Division = Equals (Will perform the final calculation) C Clear (Will clear the text box) There will be no maximize or minimize buttons. The rules are these: 2 A user enters a number (in the app you’ll use the datatype Decimal) and they will then click an operation button. Then they can enter another number and if they press equals then you’re done and the result will be displayed. No other inputting of numbers is allowed. If they don’t press equals and instead click another operation, then clear the textbox and allow them to enter another number. They can so this as many times as they like. Once the equals button is pressed make the text box read only and disable all of the buttons (Except for C) until C (clear) is clicked and then re-enable the buttons, clear and enable the text box and allow them to start again. So, if they enter 30, then click -, then enter 5, and then press = (equals) then 25 will be displayed in the textbox. The textbox will be read-only and all of the buttons except for the C (clear) button will be disabled. Once they click C (Clear) all of the buttons will be enabled, the textbox will be enabled, and cleared. Then they can start again. If they enter 30, and the – (Minus), and then 5, and then * (Multiply), then 5, and then = (equals) then 125 will be displayed in the box that is read-only, and all of the buttons except for the C button will be disabled. In this application you’ll be coding for bad input. So if they type in anything but a valid decimal you’re going to alert them (Use a messagebox) that their input was invalid. Allow them to enter new input. Of course this will happen on the operation click (Either +, -, *, /, or =). Also, you’ll have to code for division by zero. So, if they type in a number, say 5, then / and then 0, then you’ll message box them to say 3 they cannot divide by zero. Then allow them to re-enter their input. Use Decimal.TryParse to check all numbers for validity.

this is my code: (there are a error and couldn't fix it so please help me)

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 Project05
{
public partial class Form1 : Form

{
Decimal num1, num2, ans;
String op;
int count;
bool div = false;
Decimal number;

private bool TestValue(String numTest)
{
bool test = decimal.TryParse(numTest, out number);
if (test == false)
{
MessageBox.Show(" You goofed up something");
}
textBox1.Clear();
textBox1.Focus();
return test;
}

public Form1()
{
InitializeComponent();
}

private void button3_Click(object sender, EventArgs e)//Add button
{

//decimal number;
div = false;
if (TestValue(textBox1.Text))
{
num1 = number;
}
count = 2;
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)//subtract Button
{
div = false;
if (textBox1.Text != "")
{
//decimal number;
if (TestValue(textBox1.Text))
{
num1 = number;
}
count = 1;
}
}

private void button4_Click(object sender, EventArgs e)//Mutiply Button
{
div = false;
if (TestValue(textBox1.Text))
{

num1 = number;
}
count = 3;

}

private void button5_Click(object sender, EventArgs e)//divide Button
{
div = true;

if (TestValue(textBox1.Text))
{
num1 = number;
}
count = 4;

}

private void button6_Click(object sender, EventArgs e)//equal
{
div = false;
compute(count);
button1.Enabled = true;

}

private void button1_Click(object sender, EventArgs e)//Clear button
{
div = false;
textBox1.Clear();
textBox1.Focus();
count = 0;
}
public void compute(int count)
{
switch (count)
{
case 1:
ans = num1 - float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 2:
ans = num1 + float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 3:
ans = num1 * float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 4:
if (float.Parse(textBox1.Text) == 0)
{
MessageBox.Show(" You Can Not Divide by 0!!");
}
else
{
ans = num1 / float.Parse(textBox1.Text);
}
textBox1.Text = ans.ToString();
break;
default:
break;
}

}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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 Project05
{
public partial class Form1 : Form

{
Decimal num1, num2, ans;
String op;
int count;
bool div = false;
Decimal number;

private bool TestValue(String numTest)
{
bool test = decimal.TryParse(numTest, out number);
if (test == false)
{
MessageBox.Show(" You goofed up something");
}
textBox1.Clear();
textBox1.Focus();
return test;
}

public Form1()
{
InitializeComponent();
}

private void button3_Click(object sender, EventArgs e)//Add button
{

//decimal number;
div = false;
if (TestValue(textBox1.Text))
{
num1 = number;
}
count = 2;
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)//subtract Button
{
div = false;
if (textBox1.Text != "")
{
//decimal number;
if (TestValue(textBox1.Text))
{
num1 = number;
}
count = 1;
}
}

private void button4_Click(object sender, EventArgs e)//Mutiply Button
{
div = false;
if (TestValue(textBox1.Text))
{

num1 = number;
}
count = 3;

}

private void button5_Click(object sender, EventArgs e)//divide Button
{
div = true;

if (TestValue(textBox1.Text))
{
num1 = number;
}
count = 4;

}

private void button6_Click(object sender, EventArgs e)//equal
{
div = false;
compute(count);
button1.Enabled = true;

}

private void button1_Click(object sender, EventArgs e)//Clear button
{
div = false;
textBox1.Clear();
textBox1.Focus();
count = 0;
}
public void compute(int count)
{
switch (count)
{
case 1:
ans = num1 - float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 2:
ans = num1 + float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 3:
ans = num1 * float.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 4:
if (float.Parse(textBox1.Text) == 0)
{
MessageBox.Show(" You Can Not Divide by 0!!");
}
else
{
ans = num1 / float.Parse(textBox1.Text);
}
textBox1.Text = ans.ToString();
break;
default:
break;
}

}
}
}

Add a comment
Know the answer?
Add Answer to:
C# Windows Form Application (CALCULATOR): (This is the instruction below): Windows Calculator that will going to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have...

    C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have 2 Labels (each one of them assigned only to Celsius and Fahrenheit), 2 TextBoxes (each one of them assigned only to Celsius and Fahrenheit), only 1 Convert Button, 1 Clear Button, and 1 Exit Button. Also, 1 Error message label which will display the error messages. The application should only allow the user to enter the desired temperature just in one of the TextBoxes...

  • Program using visual basic.net You will create a very simple two numbers calculator with save options;...

    Program using visual basic.net You will create a very simple two numbers calculator with save options; here is the specifications for the application. Create a form divided vertically in two halves with right and left panels 1- In the left panel you will create the following control, the label or the value of the control will be in "" and the type of the control will in [] a- "First Number" [textbox] b- "Second number" [texbox] c- "Result" [textbox] -...

  • 7 1.5 By organizing reusable codes to a C++ class named "Sample.cpp", which of the following...

    7 1.5 By organizing reusable codes to a C++ class named "Sample.cpp", which of the following is the correct way to import the reusable codes to another C++ file named "Test.cpp"? #define "Sample.cpp" #include "Sample.cpp" #copy "Sample.cpp" #using "Sample.cpp" #import "Sample.cpp" 28 1.5 Given the following code, which can assign "appletree" to the "textBox1" control as caption? TextBox textBoxl; textBox1-> Caption="appletree"; textBox1.Text ="appletree"; textBox1.Caption="appletree"; textBox1.Text = "appletree"; textBox1-> Caption("appletree"); 109 1.5 Given the following code, which can register a "SelectedIndexChanged"...

  • C# Temperature Converter Application: I have most of the application complete I just need only help...

    C# Temperature Converter Application: I have most of the application complete I just need only help with error messages. My instructor wants me to show four error messages inside an error message label (not a message box) and all of the error messages should appear inside error message label. The four error messages should appear when: 1: User enters data inside both Celsius and fahrenheit text boxes: “You should enter data in only one textbox. Press Clear to start over.”...

  • Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game si...

    Project 2 – Memory Match Game Purpose This Windows Classic Desktop application plays a simple matching game. The game simulates a card game where the cards a placed face down and the player flips over pairs of cards in an attempt to find matching cards.   Program Procedure Display a 4x4 grid of “face down” cards. Assign the letters A through H randomly to the cards in pairs. Allow the user to click on a card to “flip” it over and...

  • I need help with this problem in Visual Basic 2012: Write a program that allows the...

    I need help with this problem in Visual Basic 2012: Write a program that allows the user to specify two numbers and then adds, subtracts, multiplies, or divides them when the user clicks on the appropriate button. The output should give the type of arithmetic performed and the result. Whenever one of the numbers in an input text box is changed, the output text box should be cleared. Also, if the number 0 is entered into the second text box,...

  • Hi everyone, For my Assignment I have to use C# in order to create a validation...

    Hi everyone, For my Assignment I have to use C# in order to create a validation form and include the following things to register and validate: Email Address, Username, Password, Retype Password, and a Submit Button. I have figured out some of the code for the Email Address validation: 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 Validation4 {     public partial class Form1 : Form     {        ...

  • C# I am having trouble this program. So far my temperature converter program is converting temps...

    C# I am having trouble this program. So far my temperature converter program is converting temps from C to F. However, whenever I try to convert F to C, it's keep crashing and displaying an error message, which I can not figure it out and do not know how to fix it. Attached are two screenshots are of message. Do you know what is causing the issue? I would much appreciate your assistance. namespace Temp Conv { public partial class...

  • Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the valu...

    Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...

  • Create a windows form application in c# The form must look like a calculator and do...

    Create a windows form application in c# The form must look like a calculator and do the following. Add, subtract, multiply, and divide. Account for division by zero. Show at least two decimal places. Retain the last number on the window so that, when the user opens the calculator the next time, the number that was in the window at the last close appears. Have a memory, so that users can store values and recall them. Operate with a mouse...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT