I could really use some help finishing this question I the code must be a GUI an
ID: 3584830 • Letter: I
Question
I could really use some help finishing this question
I the code must be a GUI and I can only figure out how to do it as a console application
The code must be in C# and must be a basic as possible because I am a beginner
I have a maximum value entered to show highest number out of the 10 when sorted, I don't know how I should properly set it up to show the second number that is largest out of the set.
---------------------------------------------------------------------------
Use GUI for input and output.
(Find the Two Largest Number) The process of finding the maximum value (i.e., the largest of a group of values) is used frequently in computer applications.
For example, an app that determines the winner of a sales contest would input the number of units sold by each salesperson. The salesperson who sells the most units wins the contest.
Suggestion: first Write pseudocode, then a C# app that takes a user inputs: a series of 10 integers, then determines and displays the largest integer. <
Your app should use at least the following three variables: a) counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input and to determine when all 10 numbers have been processed). b) number: The integer most recently input by the user. c) largest: The largest number found so far d) find the second largest value - for a full credit! e) [Note: You may input each number only once.]
Here is my code below
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 A1_E2
{
public partial class LargestNumbers : Form
{
private object ex;
private void btnCalculate_Click(object sender, EventArgs e)
{
int max = Int32.MaxValue;
int min = Int32.MinValue;
try
{
List<TextBox> Iboxes = GetTextBoxes();
foreach (TextBox tBox in Iboxes)
{
if (false == string.IsNullOrEmpty(tBox.Text))
{
int iBoxVal = Convert.ToInt32(tBox.Text);
if (iBoxVal > max)
{
max = iBoxVal;
}
}
if (max != Int32.MaxValue)
{
txtLargeNum.Text = max.ToString();
}
else
{
MessageBox.Show("Please enter a valid number.");
}
}
}
catch (FormatException fx)
{
Console.WriteLine("btnCalculate_Click()Format Exception Handled:" + fx);
MessageBox.Show("Please enter only numbers.");
}
catch(Exception ex)
{
Console.WriteLine("btnCalculate_Click()Exception Handled:" + ex);
MessageBox.Show(ex.Message);
}
}
private List<TextBox> GetTextBoxes()
{
List<TextBox> list = new List<TextBox>();
try
{
foreach (Control ctrl in this.Controls)
{
if(ctrl is TextBox)
{
list.Add((TextBox)ctrl);
}
}
}
catch(Exception ex)
{
Console.WriteLine("GetTextBoxes() Exception Handled:" + ex);
}
return list;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Naming of text boxes
Largest Number Please Input 10 Numbers Calculate Exit Largest Number: Second NumberExplanation / Answer
At the end of btnCalculate_click() call this function:
void FindSecondLargestNumber()
{
try
{
List<int> sortedList = new List<int>();
sortedList.Add(Convert.ToInt32(textBox1.Text));
sortedList.Add(Convert.ToInt32(textBox2.Text));
sortedList.Add(Convert.ToInt32(textBox3.Text));
sortedList.Add(Convert.ToInt32(textBox4.Text));
sortedList.Add(Convert.ToInt32(textBox5.Text));
sortedList.Add(Convert.ToInt32(textBox6.Text));
sortedList.Add(Convert.ToInt32(textBox7.Text));
sortedList.Add(Convert.ToInt32(textBox8.Text));
sortedList.Add(Convert.ToInt32(textBox9.Text));
sortedList.Add(Convert.ToInt32(textBox10.Text));
sortedList.Sort();
foreach (int item in sortedList)
{
if (item != Convert.ToInt32(txtLargeNum.Text))
{
//Use the name of your textbox to store second largest number here instead of txtSecondLargeNum
txtSecondLargeNum.Text = item;
}
}
}
catch(Exception ex)
{
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.