Question
Hey guys Heres the problem and what I'm having issues with is calling the method and outputting the reults to the textbox with the label
Hey guys
Heres the problem and what I'm having issues with is calling the method and outputting the reults to the textbox with the label "Results" as well as rounding the decimal to 4 places.
"In this exercise, youll create a simple calculator for the bookstore to use at C-Sharp University. The calculator will accepts two values and an operator from the user and then performs the requested operation.
1. Start Visual Studio.
2. Click the Create Project hyperlink or use the File-New Project menu option.
3. In the New Project dialog box type a name for the projectname the project Lab6_7- SectionTime-YourLastName-YourFirstName
4. Change the forms File Name property from Form1.vb to a new name Lab6.cs
5. Change the title of the form as shown above. 6. Add labels, text boxes, and buttons to the default form and set the properties of the form and its controls so they appear as shown above. When the user presses the Enter key, the Click event of the Calculate button should fire. When the user presses the Esc key, the Click event of the Exit button should fire.
7. Code a private method named Calculate that performs the requested operation and returns a decimal value. Initialize the return value to zero. Use if else if logic to decide what operator is being used and then calculate a result. This method should accept the following arguments:
decimal Value 1 The value entered for the first operand. string Operator 1 One of these four operators: +, -, *, or /. decimal Value 2 The value entered for the second operand.
Example: decimal result = 0; if (operator1 == "+") result = value1 + value2; else if (operator1 == "-") result = value1 - value2; etc..
8. Create an event handler for the Click event of the Calculate button. This event handler should get the two numbers and Values the user enters, call the Calculate method to get the result of the calculation, display the result rounded to four decimal places, and move the focus to the Value 1 text box.
9. Create an event handler for the Click event of the Exit button that closes the form.
10. Create an event handler that clears the Result text box if the user changes the text in any of the other text boxes. A wiring event will need to be created for all input textboxes.
11. Test the application to be sure it works correctly"
Here's the code I currently have:
"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 Lab6_7_sectionTime_lastName_firstName { public partial class Lab6 : Form {
public Lab6() { InitializeComponent(); }
private void Lab6_Load(object sender, EventArgs e) {
}
private void btnCalculate_Click(object sender, EventArgs e) { decimal value1 = Convert.ToDecimal(this.txtValue1.Text); decimal value2 = Convert.ToDecimal(this.txtValue2.Text); string operator1 = Convert.ToString(this.txtOperator.Text);
decimal totalResult = this.GetResult(decimal value1, decimal value2, string operator1);
}
private void btnExit_Click(object sender, EventArgs e) { this.Close(); }
private decimal GetResult(decimal value1, decimal value2, string operator1) { decimal result = 0;
if (operator1 == "x") { result = value1 * value2; }
else if (operator1 == "+") { result = value1 + value2; }
else if (operator1 == "-") { result = value1 - value2; }
else if (operator1 == "/") { result = value1 / value2; }
return result; } } "
And here's what the form looks like:
og C Sharp U Simple calcula Value 1: Operator: Value 2: Result: Calculate ExitStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started