Question

calculator.cs x Prearam S Miscellaneous Files ator.Designer.c s Calculato 1 曰using Systemi 2 using System.Collections.Generic
rosoft Visual Studi oject Debug Team Tools Test Analyce Window Help Attach calculater.Designerc //Exit out of method return;
0-24 culatores-Microsoft Visual Studio dia View Project Debug Team Tools Test Ansyce Window Help ellaneous Files Caculator.ca
24 tor.cs Microsoft Visual Studio View Project Debug Team Tools Test Analyze Window Help Attach. calculator Designer.c ous Fi
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 to the defult positions
-displaymessge must display messge box to the user displaying such as “5+8=12”

calculator.cs x Prearam S Miscellaneous Files ator.Designer.c s Calculato 1 曰using Systemi 2 using System.Collections.Generic; using System.ComponentModel; 4 using System.Data; s using System.Drawing; 6 using System.Linq 7using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms 18 11 日namespace Calculator 12 13 public partial class calculator: Form 14 15 16 E 17 18 19 28 21 public calculator) InitializeComponent ) //Set the default focus to the first Textbox firstNumInput.Focus) 23 24 E 25 26 private void calculateButton Click(object sender, EventArgs e) //Variables to be used double firstNumber; double secondNumber 28 29 double total; 31 //Get and Validate first number if (Idouble.TryParse(firstluminput.Text, out firstNumber)) 32 E //Display Error to user Messageßox. Show("Please insert a valid number.") 35 36 37 38 39 //Switches focus to first textbox firstNumInput.FocusO //Exit out of method return; //Get and Validate second number if (Idouble.TryParse(secondNumInput.Text, out secondNumber)) 45曰 46 //Display Error to user MessageBox. Show("Please insert a valid number.") //Switches focus to second textbox secondNumInput. Focus); //Exit out of method returnj 48 51 52 53
rosoft Visual Studi oject Debug Team Tools Test Analyce Window Help Attach calculater.Designerc //Exit out of method return; //Get Options and Calculate // Addition (+ ) if (addition.Checked) //Calc total total firstNumber+ secondNumber: //Display MessageBox with the result MessageBox.Show( "Your total isnfirstNumber+secondNumbertotal)i //Reset the focus to the first textbox firstNumInput.Focus) //Reset Input firstNuminput.Text secondNumInput.Text // Subtraction) if (subtraction.Checked) //Calculate Total total firstNumber - secondNumber; //Display MessageBox with the result MessageBox . Shon("Your total is : Vn. + firsthuber + " . " + secondumber + “ -" + total); //Reset the focus to the first textbox firstNumInput.FocusO //Reset Input firstNumInput.Text secondnuninput.Text .."; /ISwitches radiobuttons to default addition.Checked-true // Mulitplication() if (multiplication.Checked) //Calculate Total total firstNumber secondNumber; //Display MessageBox with the result MessageBox, Show("Your total is n" firstNumberecondiumber+ total): //Reset the focus to the first textbox
0-24 culatores-Microsoft Visual Studio dia View Project Debug Team Tools Test Ansyce Window Help ellaneous Files Caculator.calculator HessageBox.Show Your total is : n firstNumbersecondilumber total)i //Reset the focus to the first textbox firstNumInput.Focus) //Reset Input firstNumInput.Text secondNuminput.Text //Switch radiobuttons to default addition.Checked true // Division ) if (division.Checked) //Second number should not be zero //Display error to user Messagebox.Show"Cannot divide by zero." //Switch focus to invalid TextBox secondMrInput·Focus(); //Exit out of nethod 6 //Calculate Total total firstNumber / secondNumber 32 3 //Display MessageBox with the result MessageBox. Show"Your total is : InfirstNumbersecondlumber+total); 6 8 เอ $2 //Reset the focus to the first textbox firstiumInput.Focus)i / /Reset Input firstNumInput.Text secondliumInput. Text //Switch radiobuttons to default addition.Checked-true //Modulus (%) if (modulus,Checked) //Calculate Total total . firstu ber % secondiueber; //Display MessageBox with the result MessageBox. Show "Your total isnfirstlurber nod+ secondlusber"+total)
24 tor.cs Microsoft Visual Studio View Project Debug Team Tools Test Analyze Window Help Attach. calculator Designer.c ous Files Calculator.calculator //Display MessageBox with the result HessageBox.Show( "your total is : In+ firstumber +mod secondlumber+total): //Reset the focus to the first textbox firstNuminput.Focus(); //Reset Input firstNumInput. Text secondNumInput. Text //Switch radiobuttons to default addition.Checked true // Power ( Pow) // Reset: Click Resets the input private void reset Click(object sender, EventArgs e) //Reset the focus to the first textbox firstNuminput.Focus) //Reset input firstNumInput.Text secondNumInput. Text //Switch radiobuttons to default addition.Checked true; // Close: Click - Closes the progran private void close_click(object sender, Eventangs e) this.Close)i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

Calculator First Number Second Number: Your total is: 2+4-6 0 Add O Subtract ° Multiply ° Divide ° Modulus OK Calculate Reset

Add a comment
Know the answer?
Add Answer to:
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...
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
  • 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] -...

  • 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...

  • Visual Studio Code C# Well Document everyline saying what the code does. Include designer code and...

    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...

    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...

    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 ...

    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...

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