Question

Create a window form that will prompt the user to enter any 4 numbers and it...

Create a window form that will prompt the user to enter any 4 numbers and it will return sorted output. Store values in a list and use Add method to add values visual studio 2019 C#

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

Below is the required code. It is explained inside the code using comments.

using System;
using System.Collections.Generic;
using System.Windows.Forms;

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

        private void btnSort_Click(object sender, EventArgs e)
        {
            // create a list of numbers
            List<int> numbers = new List<int>();

            // read numbers from textboxes and add to the list
            numbers.Add(Convert.ToInt32(txtNum1.Text));
            numbers.Add(Convert.ToInt32(txtNum2.Text));
            numbers.Add(Convert.ToInt32(txtNum3.Text));
            numbers.Add(Convert.ToInt32(txtNum4.Text));

            // sort the list
            numbers.Sort();

            // create output string
            string output = "Sorted: ";
            for (int i = 0; i < numbers.Count; i++)
            {
                // append numbers to output string
                output += numbers[i] + " ";
            }

            // display the sorted numbers
            lblSorted.Text = output;
        }
    }
}

Please note, the name of controls on form are:

Textboxes: 'txtNum1', 'txtNum2', 'txtNum3', 'txtNum4'

Button: 'btnSort'

Below is the sample output:

Numbers Program - O X Enter number 1: Enter number 2: Enter number 3: Enter number 4: 4 35 27 Sort

. Numbers Program - O X Enter number 1: Enter number 2: Enter number 3: Enter number 4 85 4 35 27 Sort Sorted: 4 27 35 85

This completes the requirement. Let me know if you have any questions.

Thanks!

Add a comment
Know the answer?
Add Answer to:
Create a window form that will prompt the user to enter any 4 numbers and it...
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
  • MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers....

    MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers. Then prompt the user again to input as many numbers as they choose. Stop the program by inputting-1. Then, display the largest number and second largest number in the command window once the user kills the program. The built-in max function cannot be used. The figure below is an example of what the command window should look like when the code is ran. First...

  • Write a C++ program that prompts the user to enter two numbers. Then prompt the user...

    Write a C++ program that prompts the user to enter two numbers. Then prompt the user to select from the following options: a. Add the numbers. b. Multiply the numbers. c. Terminate the program Use the appropriate control structures (loops, if else, switch-case, etc) to make your program as short and efficient as possible. Minor syntax errors are forgiven in this exercise; just focus on the correct structure, declarations and sequence of instructions

  • Write a program that will compute the user annual salary. Prompt the user the enter (1)...

    Write a program that will compute the user annual salary. Prompt the user the enter (1) the weekly salary. Store the information in a double variable. Prompt the user to enter the number of weeks worked in a year. Use an int variable for that. Write code that will compute the user's Annual salary. Gross salary is salary before any deductions are taken. Update the code and prompt the user to enter the federal tax rate and the state's tax...

  • Instructions We're going to create a program which will allow the user to add values to a list, p...

    Instructions We're going to create a program which will allow the user to add values to a list, print the values, and print the sum of all the values. Part of this program will be a simple user interface. 1. In the Program class, add a static list of doubles: private statie List<double> _values new List<double>) this is the list of doubles well be working with in the program. 2. Add ReadInteger (string prompt) , and ReadDouble(string prompt) to the...

  • C++ TrainStation Program Create a function called searchForSchedules that will: - prompt a user to enter...

    C++ TrainStation Program Create a function called searchForSchedules that will: - prompt a user to enter a scheduleId - search for arrival and departure times of trains based on a trains ID number Create a function called editSchedules that will: - allow the user to edit the fields for a given schedule that is in the linked list. - the program must prompt the user to enter the scheduleId as the key to find the schedule to edit. Print a...

  • Write a program in Java language to prompt the user to enter 3 integers (A, B,...

    Write a program in Java language to prompt the user to enter 3 integers (A, B, and C) then display these numbers from the lowest to the highest (sorted ascendingly) . Note that there are 6 different cases to handle proper order. As an example, a user entered 10 for A, 5 for B and 14 for C: the output of the program should look like this Enter number A? 10 Enter number B? 5 Enter number C? 14 Your...

  • hii, can you please help me to implement a program in c# that creates a form...

    hii, can you please help me to implement a program in c# that creates a form and make automatic schedule for any store. in visual studio 2019, create a schedule maker . how to read a file in window form application

  • Write a test program that prompt the user to enter seven numbers, stores them in an...

    Write a test program that prompt the user to enter seven numbers, stores them in an array list and do the following: 1. Displays its elements (numbers) in increasing order by invoking a method with the following header that sorts the array: public static void sort(ArrayList<Integer>list) 2. Write a method that returns and displays the sum of all numbers (elements) of the ArrayList. Using the following header: public static double sum(ArrayList<Integer>list) 3. Write a method that removes the duplicate numbers...

  • write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mam...

    write a programming code for the following problem using Visual Basic Studio VB. Write a program that will allow the user to enter series of mumbers and will give some useful statistics about the mambers Enter Numbers Button Click-Allow the user to enter series of nambers using imput dialog boxes. Use a loop and add the numbers to the listBox as they are input.. Prompt the user to enter"x" to stop addang numbers. Compute Statistics Button Click-Compute the following statistics...

  • 1. print mesage to user to prompt user to enter 10 numbers 2 have program accept...

    1. print mesage to user to prompt user to enter 10 numbers 2 have program accept 10 numbers from user and populate 10 occurrances of an array (use a loop to do this). 3. print message to user to advise user contents of array follows 4. have program display array contents (use loop to do this) end program comment in java please

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