Below is the solution:
using System;
using System.Windows.Forms;
namespace Calculator2
{
public partial class Calculator : Form
{
public
Calculator()
{
InitializeComponent();
}
private void
Calculator_Load(object sender, EventArgs e)
{
firstNumInput.Focus();
}
private void
calculateButton_Click(object sender, EventArgs e)
{
double firstNumber;
double secondNumber;
double total;
if(isValidate(firstNumInput.Text)){
MessageBox.Show("Input first Number correct");
firstNumInput.Focus();
}
else if (isValidate(secondNumInput.Text))
{
MessageBox.Show("Input second Number correct");
secondNumInput .Focus();
}
else
{
firstNumber = Convert.ToDouble(firstNumInput.Text);
secondNumber = Convert.ToDouble(secondNumInput.Text);
if (addition.Checked)
{
total = firstNumber + secondNumber;
MessageBox.Show("Your total is: \n"+firstNumber + "+"+secondNumber+
"="+ total.ToString());
firstNumInput.Text = ""; //clear the textbox
secondNumInput.Text = ""; //clear the textbox
firstNumInput.Focus(); //focus the textbox
}
else if (subtraction.Checked)
{
total = firstNumber - secondNumber;
MessageBox.Show("Your total is: \n" + firstNumber + "-" +
secondNumber + "=" + total.ToString());
firstNumInput.Text = ""; //clear the textbox
secondNumInput.Text = ""; //clear the textbox
firstNumInput.Focus(); //focus the textbox
addition.Checked = true; //set the default radio button addition to
checked
}
else if (multiplication.Checked)
{
total = firstNumber * secondNumber;
MessageBox.Show("Your total is: \n" + firstNumber + "*" +
secondNumber + "=" + total.ToString());
firstNumInput.Text = ""; //clear the textbox
secondNumInput.Text = ""; //clear the textbox
firstNumInput.Focus(); //focus the textbox
addition.Checked = true; //set the default radio button addition to
checked
}
else if (division.Checked)
{
if (secondNumber == 0) //check for the second number is not
zero
{
MessageBox.Show("Cannot divided by zero");
secondNumInput.Focus(); //focus the textbox
return;
}
total = firstNumber / secondNumber;
MessageBox.Show("Your total is: \n" + firstNumber + "/" +
secondNumber + "=" + total.ToString());
firstNumInput.Text = ""; //clear the textbox
secondNumInput.Text = ""; //clear the textbox
firstNumInput.Focus(); //focus the textbox
addition.Checked = true; //set the default radio button addition to
checked
}
else if (modulus .Checked)
{
total = firstNumber % secondNumber;
MessageBox.Show("Your total is: \n" + firstNumber + "%" +
secondNumber + "=" + total.ToString());
firstNumInput.Text = ""; //clear the textbox
secondNumInput.Text = ""; //clear the textbox
firstNumInput.Focus(); //focus the textbox
addition.Checked = true; //set the default radio button addition to
checked
}
}
}
//function to
validate the input box
private bool
isValidate(string num) //validate the input number
{
double number;
if (!double.TryParse(num, out number)) //check for the inputis
number
return true; //return true
else
return false; //return false if not number
}
private void
close_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void
reset_Click(object sender, EventArgs e)
{
firstNumInput.Text = "";
secondNumInput.Text = "";
firstNumInput.Focus(); //focus on first input box
addition.Checked= true; //set the default radio button addition to
checked
}
}
}
output:
how to add methods into thjs code using C# on visual studio? -validatetextbox should return a true false depending if input is valid -resetinput should clear all input and restart radiobuttons...
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] -...
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...
Visual Studio Code C#
Well Document everyline saying what the code
does.
Include designer code and .cscode
Extra 6-1 Create a simple calculator In this exercise, you'l1 create a form that accepts two operands and an operator from the user and then performs the requested operation. Simple Calculator Operand 1: 86 Operator Operand 2 11.11 Resut 7.7408 1. Start a new project named SimpleCalculator in the Extra Exercises Chapter 06SimpleCalculator directory 2. Add labels, text boxes, and buttons to the...
If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...
This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...
C LANGUAGE. PLEASE INCLUDE COMMENTS :)
>>>>TheCafe V2.c<<<<
#include <stdio.h>
int main()
{
int fries; // A flag denoting whether they want fries or not.
char bacon; // A character for storing their bacon preference.
double cost = 0.0; // The total cost of their meal, initialized to start at 0.0
int choice; // A variable new to version 2, choice is an int that will store the
// user's menu choice. It will also serve as our loop control...