Hello Experts :)

My Name is GaYan and im still learning C# :D lol.. im a newbie :idea:

what i need to do is to create a program in C# to enter a number series and to get the the highest(largest) value and minimum(smallest) value of the entered numher series ended by a negative number !
This must use a while loop too :scared:

i have the idea about the algorithm ! hope this is correct :D :D

thier must be 3 text boxes, one is to input the numbers and other one is to display the highest and smallest numbers entered in the number series after we finish the process by making the while condition false ( by entering a negative value)

Input N
Max = N
Min = N

        while N > 0
        If N > Max
        Max = N
Else if
        N < Max
        Min = N
End If

Print "Highest value of the entered num series =" Max;
Print "smallest value of the entered num series =" Min;

So Dear Experts. Please help me to overcome this doubt over C# ! any coding explanation is greatly appreciated :icon_wink:

Thanks In Advance !

Recommended Answers

All 5 Replies

Or,

List<int> numbers = new List<int>();
numbers.Sort();
Print "Highest value = " + numbers[numbers.Count - 1].ToString()
Print "Lowest value = " + numbers[0].ToString();

bbman ,, !

I Need to use a while loop to generate the output :(
it needs to work according to the antilogarithm in the above post .. Thanks ~! can you modify this code a bit ! actually i dont want to use the list here !

! Thanks !

bbman ,, !
I Need to use a while loop to generate the output :(
it needs to work according to the antilogarithm in the above post .. Thanks ~! can you modify this code a bit ! actually i dont want to use the list here !

! Thanks !

That's not help. That would be doing your homework for you.
Read the forum rules. You need to show effort, and what better way than posting the code that you have tried so far?

We only give homework help to those who show effort

@ adatapost , yes. i have tried to do the program so far using the below code !

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        float min, max, inputz;




        private void Form1_Load(object sender, EventArgs e)
        {
            // Plese Help me out :)
        }

        private void btn_submit_Click(object sender, EventArgs e)
        {
            max = float.Parse(txt_In.Text);
            min = float.Parse(txt_In.Text);
            inputz = float.Parse(txt_In.Text);

            while (inputz != 0) // loop to check the input is negative or not
            {
                if (inputz > max)
                {
                    max = inputz();
                }

                else if (inputz > max)
                {
                    min = inputz();
                }

            }

            txt_out.Text = max + min(); // This is to show the output result when the while loop 
                                        //condition is false after entering a negative value
        }
    }
}

i didnt post the original code before because its lot of errors :(
Please try to help me out :( my class teacher is gonna kill me :(

You need an array of float to store input. Read/Input space delimited values in text_in textbox. e.g 10 20 30 40 2 40 -9

float max, min;
        private void btn_submit_Click(object sender, EventArgs e)
        {

            //Convert space delimited string into array of string
            string[] inputar = text_in.Text.Split(new string[]{" "},StringSplitOptions.RemoveEmptyEntries );
            if (inputar.Length == 0)
            {
                MessageBox.Show("No input.");
                return;
            }
            //Cast array of string into float

            float[] inputz = new float[inputar.Length];
            int i;

            for (i = 0; i < inputar.Length; i++)
            {
                inputz[i]= float.Parse(inputar[i]);
            }


            
            if (inputz[inputz.Length - 1] > 0)
            {
                MessageBox.Show("Last element must be negative number.");
                return;
            }
            max = min = inputz[0];

            i=0;
            while (inputz[i]>0)
            {
                if (inputz[i] > max)
                    max = inputz[i];
                else
                    if (inputz[i] < min)
                        min = inputz[i];

                i++;
            }


            txt_out.Text = min.ToString() + " " + max.ToString();
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.