Question

In Visual Studio, start a new C# Windows form project and call it doingMath. On the...

In Visual Studio, start a new C# Windows form project and call it doingMath. On the form, put a button, a label and four textBoxes. Name the label myanswer, the button Run, and call the textBoxes num1, num2, num3 and num4. Instantiate an array of type double called myNumbers. When we did this in the lecture, it was done as integers: int[] myarray = new int[4]; The only thing here that changes is the type is to be "double". Double is a large decimal number. double[] myarray = new double[4]; Put the values from the textboxes in the array. For example myNumber[0] = Convert.ToDouble(num1.Text); Now use a for loop to sum the array and display the final total in myAnswer

copy and paste the entire code

Homework Answers

Answer #1

Here is the solution

controls:-

1 label --------------- name : myanswer (text--------"Answer")

4 textboxes ---------------- names (num1,num2,num3,num4)

1 button ------------------- name run (text ---- "run")

code behind the button (run)

// your code start here
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace additions
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Run_Click(object sender, EventArgs e)
{
// array declaration
double[] myarray = new double[4];
// sum to collect the total
double sum = 0;

// accepting values in array from textboxes
myarray[0] = Convert.ToDouble(num1.Text);
myarray[1] = Convert.ToDouble(num2.Text);
myarray[2] = Convert.ToDouble(num3.Text);
myarray[3] = Convert.ToDouble(num4.Text);

// looping over to access the values of the array
// and the calculate the total
for (int i = 0; i < myarray.Length; i++)
{
sum += myarray[i];
}

// finally displaying the output to lable myanswer
myanswer.Text = "Answer:" + sum.ToString();
}
}
}
// Code ends here

Here is the sample output:-

here is the screenshot of the program:-

Thank You.

Know the answer?
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
Similar Questions
Create a new project in Visual Studio using C# Console Project. Declare an array of strings...
Create a new project in Visual Studio using C# Console Project. Declare an array of strings with the size of 12. Insert 12 different strings into the array. In a foreach loop display the contents of the array to the console.
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
In Visual Studio, create a program that provides the following items: 1 Textbox control 2 Picturebox...
In Visual Studio, create a program that provides the following items: 1 Textbox control 2 Picturebox control 3 int datatype 4 double datatype 5 strings 6 comment each line of code that you put into the form1.cs 7 label control 8 button control The program can be about anything you want. It should be a functional program. Program Items worth (40pts (5pts per item) ) Creativity of your program worth (30pts) Functionality worth (30pts) Submit your (form cs file) and...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of your choosing (ex: “assignment2.py”). At the top of the file paste the following: import numpy as np import random class Base_Obstacle_Map(object):     def __init__(self, length, width):         self.map = np.zeros((length, width), dtype=np.uint8)     def add_obstacle(self, x, y):         self.map[x, y] = 1     def remove_obstacle(self, x, y):         self.map[x, y] = 0     def display_map(self):         try:             import matplotlib.pyplot as plt             plt.imshow(self.map)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT